Difference between revisions of "Component: RFID (MFRC522) (Wireless)"
(XML import BR) |
(XML import) |
||
Line 7: | Line 7: | ||
|- | |- | ||
| width="20%" style="color: gray;" | Version | | width="20%" style="color: gray;" | Version | ||
− | | | + | | 3.0 (Release) |
|- | |- | ||
| width="20%" style="color: gray;" | Category | | width="20%" style="color: gray;" | Category | ||
Line 30: | Line 30: | ||
==Downloadable macro reference== | ==Downloadable macro reference== | ||
− | ===<span style="font-weight: normal;"><u><tt> | + | ===<span style="font-weight: normal;"><u><tt>CompareUID</tt></u></span>=== |
− | + | Compares the UID from the ReadCardSerial macro with 4 byte UID. | |
− | + | Returns 0 if the addresses match. | |
− | + | '''Parameters''' | |
− | + | :[[Variable Types|BYTE]] ''Add0'' | |
− | ''' | + | :[[Variable Types|BYTE]] ''Add1'' |
+ | |||
+ | :[[Variable Types|BYTE]] ''Add2'' | ||
− | :[[Variable Types|BYTE]] '' | + | :[[Variable Types|BYTE]] ''Add3'' |
Line 49: | Line 51: | ||
− | ===<span style="font-weight: normal;"><u><tt> | + | ===<span style="font-weight: normal;"><u><tt>IsNewCardPresent</tt></u></span>=== |
− | + | Is there a card present for us to communicate with. | |
− | + | Returns 0 for no card and 1 for valid card present. | |
− | + | '''Parameters''' | |
+ | |||
+ | :''This macro has no parameters'' | ||
+ | |||
+ | |||
+ | '''Return value''' | ||
+ | |||
+ | :[[Variable Types|BYTE]] | ||
+ | |||
+ | |||
+ | ===<span style="font-weight: normal;"><u><tt>GetType</tt></u></span>=== | ||
+ | Translates the SAK (Select Acknowledge) to a PICC type | ||
'''Parameters''' | '''Parameters''' | ||
− | :[[Variable Types|BYTE]] '' | + | :[[Variable Types|BYTE]] ''sak'' |
− | :: | + | ::The SAK byte returned from PICC_Select |
Line 82: | Line 95: | ||
− | ===<span style="font-weight: normal;"><u><tt> | + | ===<span style="font-weight: normal;"><u><tt>ReadCardSerial</tt></u></span>=== |
− | + | Simple wrapper around PICC_Select. | |
− | + | Returns true if a UID could be read. | |
− | + | Remember to call PICC_IsNewCardPresent(), PICC_RequestA() or PICC_WakeupA() first. | |
+ | |||
+ | The read UID is available in the class variable uid. | ||
+ | |||
+ | '''Parameters''' | ||
+ | |||
+ | :''This macro has no parameters'' | ||
+ | |||
+ | |||
+ | '''Return value''' | ||
+ | |||
+ | :[[Variable Types|BYTE]] | ||
+ | |||
+ | |||
+ | ===<span style="font-weight: normal;"><u><tt>MifareWrite</tt></u></span>=== | ||
+ | Writes to a block of data on a MIFARE type tag | ||
'''Parameters''' | '''Parameters''' | ||
:[[Variable Types|BYTE]] ''BlockAddress'' | :[[Variable Types|BYTE]] ''BlockAddress'' | ||
+ | |||
+ | :[[Variable Types|BYTE]] ''Buffer'' | ||
+ | |||
+ | :[[Variable Types|BYTE]] ''BufferSize'' | ||
Line 99: | Line 131: | ||
− | ===<span style="font-weight: normal;"><u><tt> | + | ===<span style="font-weight: normal;"><u><tt>Select</tt></u></span>=== |
''<span style="color:red;">No additional information</span>'' | ''<span style="color:red;">No additional information</span>'' | ||
Line 106: | Line 138: | ||
'''Parameters''' | '''Parameters''' | ||
− | :[[Variable Types|BYTE]] '' | + | :[[Variable Types|BYTE]] ''ValidBits'' |
− | |||
− | :[[Variable Types|BYTE]] | + | '''Return value''' |
+ | |||
+ | :[[Variable Types|BYTE]] | ||
+ | |||
− | : | + | ===<span style="font-weight: normal;"><u><tt>StopCrypto</tt></u></span>=== |
+ | Used to exit the PCD from its authenticated state. | ||
− | + | Remember to call this function after communicating with an authenticated PICC - otherwise no new communications can start. | |
+ | '''Parameters''' | ||
− | '' | + | :''This macro has no parameters'' |
− | |||
+ | '''Return value''' | ||
− | + | :''This call does not return a value'' | |
− | |||
− | |||
− | + | ===<span style="font-weight: normal;"><u><tt>MifareRead</tt></u></span>=== | |
+ | Reads from a block of data on a MIFARE type tag | ||
'''Parameters''' | '''Parameters''' | ||
− | :[[Variable Types|BYTE]] '' | + | :[[Variable Types|BYTE]] ''BlockAddress'' |
− | : | + | |
+ | :[[Variable Types|BYTE]] ''Buffer'' | ||
− | :[[Variable Types|BYTE]] '' | + | :[[Variable Types|BYTE]] ''BufferSize'' |
'''Return value''' | '''Return value''' | ||
− | : | + | :[[Variable Types|BYTE]] |
− | ===<span style="font-weight: normal;"><u><tt> | + | ===<span style="font-weight: normal;"><u><tt>Authenticate</tt></u></span>=== |
This command manages MIFARE authentication to enable a secure communication to any MIFARE Mini, MIFARE 1K and MIFARE 4K card. | This command manages MIFARE authentication to enable a secure communication to any MIFARE Mini, MIFARE 1K and MIFARE 4K card. | ||
Line 151: | Line 187: | ||
'''Parameters''' | '''Parameters''' | ||
− | :[[Variable Types|BYTE]] '' | + | :[[Variable Types|BYTE]] ''Command'' |
::PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B | ::PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B | ||
Line 157: | Line 193: | ||
::The block number | ::The block number | ||
− | :[[Variable Types|BYTE]] '' | + | :[[Variable Types|BYTE]] ''Key'' |
− | ::Crypteo key to use | + | ::Crypteo key to use |
− | |||
− | |||
− | + | '''Return value''' | |
− | |||
− | :[[Variable Types|BYTE]] | + | :[[Variable Types|BYTE]] |
− | |||
− | |||
− | |||
− | : | + | ===<span style="font-weight: normal;"><u><tt>HaltA</tt></u></span>=== |
− | + | Instructs a PICC in state ACTIVE(*) to go to state HALT | |
− | + | '''Parameters''' | |
− | |||
− | : | + | :''This macro has no parameters'' |
− | |||
− | |||
− | |||
− | + | '''Return value''' | |
− | |||
+ | :[[Variable Types|BYTE]] | ||
− | |||
− | : | + | ===<span style="font-weight: normal;"><u><tt>ReadUIDByte</tt></u></span>=== |
+ | ''<span style="color:red;">No additional information</span>'' | ||
− | |||
− | |||
'''Parameters''' | '''Parameters''' | ||
− | :'' | + | :[[Variable Types|BYTE]] ''Index'' |
+ | ::0-9 = UID Data Bytes, 10 = UID Length, 11 = UID SAK | ||
'''Return value''' | '''Return value''' | ||
− | : | + | :[[Variable Types|BYTE]] |
Line 221: | Line 246: | ||
− | ===<span style="font-weight: normal;"><u><tt> | + | ===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>=== |
− | + | Initialises the RFID module ready for interaction with RFID tags. | |
− | |||
− | |||
'''Parameters''' | '''Parameters''' | ||
− | : | + | :''This macro has no parameters'' |
− | |||
− | + | '''Return value''' | |
− | : | + | :''This call does not return a value'' |
− | |||
− | + | ==Simulation macro reference== | |
− | + | ''This component does not contain any simulation macros'' | |
− | ===<span style="font-weight: normal;"><u> | + | ==Property reference== |
− | + | <span style="font-weight: normal;"><u>Channel</u></span> | |
− | ''' | + | This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_spi::CHANNEL''. |
− | + | SPI Channel selector | |
+ | <span style="font-weight: normal;"><u>Prescale</u></span> | ||
− | ''' | + | This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_spi::PR_SCALE''. |
− | + | Prescale option selector | |
+ | <span style="font-weight: normal;"><u>MOSI</u></span> | ||
− | + | This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_spi::MOSI''. | |
− | |||
− | + | SPI Data Out Pin SDO - Also Known as Master Out Slave In (MOSI) when used in Master mode. | |
− | + | <span style="font-weight: normal;"><u>MISO</u></span> | |
− | ''' | + | This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_spi::MISO''. |
− | + | SPI Data In Pin SDI - Also Known as Master In Slave Out (MISO) when used in Master mode. | |
+ | <span style="font-weight: normal;"><u>CLK</u></span> | ||
− | ''' | + | This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_spi::CLK''. |
− | + | SPI Clock Pin CLK - The Clock signal is driven by the SPI master. | |
+ | <span style="font-weight: normal;"><u>CS / SS</u></span> | ||
+ | This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_spi::SS''. | ||
− | + | Chip Select / Slave Select Pin | |
− | + | Master Mode: General purpose output pin used to select the remote SPI device. | |
+ | Slave Mode: Hardware chip select pin input used to select the SPI device. | ||
− | + | <span style="font-weight: normal;"><u>Reset</u></span> | |
− | <span style="font-weight: normal;"><u> | ||
− | This property is of type '' | + | This property is of type ''Single digital pin'' and can be referenced with the variable name ''reset''. |
− | + | MFRC522 Reset Pin | |
+ | <span style="font-weight: normal;"><u>Label</u></span> | ||
+ | This property is of type ''Line of text'' and can be referenced with the variable name ''label''. | ||
− | <span style=" | + | ''<span style="color:red;">No additional information</span>'' |
− | |||
− | |||
− | <span style="font-weight: normal;"><u> | + | <span style="font-weight: normal;"><u>Scope Traces</u></span> |
− | This property is of type '' | + | This property is of type ''True or false'' and can be referenced with the variable name ''cal_spi::ScopeTraces''. |
− | + | Selects if the scope traces are automatically generated or not | |
− | <span style="font-weight: normal;"><u> | + | <span style="font-weight: normal;"><u>Console Data</u></span> |
− | This property is of type '' | + | This property is of type ''True or false'' and can be referenced with the variable name ''cal_spi::ConsoleData''. |
− | + | Selects if the console data is automatically generated or not | |
− | <span style="font-weight: normal;"><u> | + | <span style="font-weight: normal;"><u>Injector</u></span> |
− | This property is of type '' | + | This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_spi::Injector''. |
− | + | ''<span style="color:red;">No additional information</span>'' | |
− | |||
− | <span style=" | ||
− | |||
− | |||
− | |||
− |
Revision as of 10:31, 9 May 2018
Author | Ben Rowland and STibor |
Version | 3.0 (Release) |
Category | Wireless |
Contents
RFID (MFRC522) component
Functions designed to work with the MFRC522 contactless reader IC. The MFRC522 supports all variants of the MIFARE Mini, MIFARE 1K, MIFARE 4K, MIFARE Ultralight, MIFARE DESFire EV1 and MIFARE Plus RF identification protocols.
Examples
Here is a basic example program that shows various ways the MFRC522 RFID reader can be used.
A switch is connected to pin A0, when the switch is active the program will read the ID of the RFID tag and display it on the LCD.
When the switch is not active the program will check the ID of a RFID tag with a pre-programmed ID, if the ID bytes match then the LCD will display a Welcome message and the LED connected to pin A1 will light for two seconds. This pin could then be used to drive a solenoid and open a security door.
MFRC522 Example
Downloadable macro reference
CompareUID
Compares the UID from the ReadCardSerial macro with 4 byte UID.
Returns 0 if the addresses match.
Parameters
- BYTE Add0
- BYTE Add1
- BYTE Add2
- BYTE Add3
Return value
IsNewCardPresent
Is there a card present for us to communicate with.
Returns 0 for no card and 1 for valid card present.
Parameters
- This macro has no parameters
Return value
GetType
Translates the SAK (Select Acknowledge) to a PICC type
Parameters
- BYTE sak
- The SAK byte returned from PICC_Select
Return value
AntennaOff
Switches off the RFID antenna to save power.
The antenna must be switched on again before communicating with an RFID tag.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
ReadCardSerial
Simple wrapper around PICC_Select.
Returns true if a UID could be read.
Remember to call PICC_IsNewCardPresent(), PICC_RequestA() or PICC_WakeupA() first.
The read UID is available in the class variable uid.
Parameters
- This macro has no parameters
Return value
MifareWrite
Writes to a block of data on a MIFARE type tag
Parameters
- BYTE BlockAddress
- BYTE Buffer
- BYTE BufferSize
Return value
Select
No additional information
Parameters
- BYTE ValidBits
Return value
StopCrypto
Used to exit the PCD from its authenticated state.
Remember to call this function after communicating with an authenticated PICC - otherwise no new communications can start.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
MifareRead
Reads from a block of data on a MIFARE type tag
Parameters
- BYTE BlockAddress
- BYTE Buffer
- BYTE BufferSize
Return value
Authenticate
This command manages MIFARE authentication to enable a secure communication to any MIFARE Mini, MIFARE 1K and MIFARE 4K card.
All keys are set to FFFFFFFFFFFFh at chip delivery.
The authentication is described in the MFRC522 datasheet section 10.3.1.9.
Parameters
- BYTE Command
- PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B
- BYTE BlockAddress
- The block number
- BYTE Key
- Crypteo key to use
Return value
HaltA
Instructs a PICC in state ACTIVE(*) to go to state HALT
Parameters
- This macro has no parameters
Return value
ReadUIDByte
No additional information
Parameters
- BYTE Index
- 0-9 = UID Data Bytes, 10 = UID Length, 11 = UID SAK
Return value
AntennaOn
Switches on the RFID antenna.
Called as part of the Initialise macro.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
Initialise
Initialises the RFID module ready for interaction with RFID tags.
Parameters
- This macro has no parameters
Return value
- This call does not return a value
Simulation macro reference
This component does not contain any simulation macros
Property reference
Channel
This property is of type Fixed list of ints and can be referenced with the variable name cal_spi::CHANNEL.
SPI Channel selector
Prescale
This property is of type Fixed list of ints and can be referenced with the variable name cal_spi::PR_SCALE.
Prescale option selector
MOSI
This property is of type Single digital pin and can be referenced with the variable name cal_spi::MOSI.
SPI Data Out Pin SDO - Also Known as Master Out Slave In (MOSI) when used in Master mode.
MISO
This property is of type Single digital pin and can be referenced with the variable name cal_spi::MISO.
SPI Data In Pin SDI - Also Known as Master In Slave Out (MISO) when used in Master mode.
CLK
This property is of type Single digital pin and can be referenced with the variable name cal_spi::CLK.
SPI Clock Pin CLK - The Clock signal is driven by the SPI master.
CS / SS
This property is of type Single digital pin and can be referenced with the variable name cal_spi::SS.
Chip Select / Slave Select Pin
Master Mode: General purpose output pin used to select the remote SPI device.
Slave Mode: Hardware chip select pin input used to select the SPI device.
Reset
This property is of type Single digital pin and can be referenced with the variable name reset.
MFRC522 Reset Pin
Label
This property is of type Line of text and can be referenced with the variable name label.
No additional information
Scope Traces
This property is of type True or false and can be referenced with the variable name cal_spi::ScopeTraces.
Selects if the scope traces are automatically generated or not
Console Data
This property is of type True or false and can be referenced with the variable name cal_spi::ConsoleData.
Selects if the console data is automatically generated or not
Injector
This property is of type Fixed list of ints and can be referenced with the variable name cal_spi::Injector.
No additional information