Difference between revisions of "Component: RFID (MFRC522) (Wireless)"

From Flowcode Help
Jump to navigationJump to search
(XML import BR)
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
+
{| style="width:50%"
 
 
{| width="50%"
 
 
|-
 
|-
| width="20%" style="color: gray;" | Author
+
| width="20%" style="color:gray;" | Author
 
| Ben Rowland and STibor
 
| Ben Rowland and STibor
 
|-
 
|-
| width="20%" style="color: gray;" | Version
+
| width="20%" style="color:gray;" | Version
| 2.0 (Release)
+
| 3.0
 
|-
 
|-
| width="20%" style="color: gray;" | Category
+
| width="20%" style="color:gray;" | Category
 
| Wireless
 
| Wireless
 
|}
 
|}
  
  
 +
==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.
  
==[[File:Component Icon 3f8d29a6_40a6_4d5e_a254_190c86d9ebb7.png|Image]] RFID (MFRC522) component==
+
==Component Source Code==
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==
+
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_MFRC522.fcfx FC_Comp_Source_MFRC522.fcfx]
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.
+
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_MFRC522.fcfx FC_Comp_Source_MFRC522.fcfx]
  
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.
+
==Detailed description==
{{Fcfile|MFRC522Example.fcfx|MFRC522 Example}}
 
  
==Downloadable macro reference==
 
  
===<span style="font-weight: normal;"><u><tt>WriteBlock</tt></u></span>===
 
Writes the contents of the 16-byte data buffer to the RFID block.
 
  
The data comes from the DataBuffer which can be set using the
 
  
WriteDataBuffer macro.
 
  
Returns 0 for a succesful write.
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''BlockAddress''
 
  
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
 
  
  
===<span style="font-weight: normal;"><u><tt>ReadDataBuffer</tt></u></span>===
 
Reads a byte from the receive data buffer.
 
  
ID locations are 0-4
 
  
Data locations are 0-15
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Index''
 
::Locations 0-15
 
  
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
 
  
  
===<span style="font-weight: normal;"><u><tt>AntennaOff</tt></u></span>===
 
Switches off the RFID antenna to save power.
 
  
The antenna must be switched on again before communicating with an RFID tag.
 
  
'''Parameters'''
+
''No detailed description exists yet for this component''
  
:''This macro has no parameters''
+
==Examples==
  
  
'''Return value'''
 
  
:''This call does not return a value''
 
  
  
===<span style="font-weight: normal;"><u><tt>ReadBlock</tt></u></span>===
 
Reads the contents of the 16-byte data buffer block on the RFID.
 
  
The receive data is stored in the data buffer and read back using the ReadDataBuffer macro.
 
  
Returns 0 for a succesful read.
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''BlockAddress''
 
  
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
 
  
  
===<span style="font-weight: normal;"><u><tt>SelectTag</tt></u></span>===
 
''<span style="color:red;">No additional information</span>''
 
  
  
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Ser0''
 
  
:[[Variable Types|BYTE]] ''Ser1''
 
  
:[[Variable Types|BYTE]] ''Ser2''
 
  
:[[Variable Types|BYTE]] ''Ser3''
 
  
:[[Variable Types|BYTE]] ''Ser4''
 
  
  
'''Return value'''
+
Here is a basic example program that reads the UID from a Mifare RFID tag and displays on an LCD. If the UID matches the UID stored in memory then a solenoid will fire allowing a door to be unlocked etc.
  
:[[Variable Types|BYTE]]
+
{{Fcfile|MFRC522_UID_Test.fcfx|Display UID}}
  
  
===<span style="font-weight: normal;"><u><tt>WriteDataBuffer</tt></u></span>===
+
Here is a basic example program to read and modify data stored on a Mifare RFID tag.
Writes a value to the 16-byte data buffer
 
  
ID locations are 0-4
+
{{Fcfile|MFRC522_Read_Write.fcfx|Read Write Test}}
  
Data locations are 0-15
 
  
'''Parameters'''
 
  
:[[Variable Types|BYTE]] ''Index''
 
::0-15
 
  
:[[Variable Types|BYTE]] ''Data''
 
  
  
'''Return value'''
 
  
:''This call does not return a value''
 
  
  
===<span style="font-weight: normal;"><u><tt>Auth</tt></u></span>===
 
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.
+
==Macro reference==
  
'''Parameters'''
+
===AntennaOff===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AntennaOff'''
 +
|-
 +
| colspan="2" | Switches off the RFID antenna to save power. The antenna must be switched on again before communicating with an RFID tag.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]] ''AuthMode''
 
::PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B
 
  
:[[Variable Types|BYTE]] ''BlockAddress''
+
===AntennaOn===
::The block number
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AntennaOn'''
 +
|-
 +
| colspan="2" | Switches on the RFID antenna. Called as part of the Initialise macro.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]] ''Key0''
 
::Crypteo key to use - Byte 0
 
  
:[[Variable Types|BYTE]] ''Key1''
+
===Authenticate===
::Crypteo key to use - Byte 1
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Authenticate'''
 +
|-
 +
| colspan="2" | 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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Command
 +
|-
 +
| colspan="2" | PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | BlockAddress
 +
|-
 +
| colspan="2" | The block number&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Key
 +
|-
 +
| colspan="2" | Crypteo key to use&nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]] ''Key2''
 
::Crypteo key to use - Byte 2
 
  
:[[Variable Types|BYTE]] ''Key3''
+
===CompareUID===
::Crypteo key to use - Byte 3
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CompareUID'''
 +
|-
 +
| colspan="2" | Compares the UID from the ReadCardSerial macro with 4 byte UID. Returns 0 if the addresses match.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Add0
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Add1
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Add2
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Add3
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]] ''Key4''
 
::Crypteo key to use - Byte 4
 
  
:[[Variable Types|BYTE]] ''Key5''
+
===GetType===
::Crypteo key to use - Byte 5
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetType'''
 +
|-
 +
| colspan="2" | Translates the SAK (Select Acknowledge) to a PICC type&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | sak
 +
|-
 +
| colspan="2" | The SAK byte returned from PICC_Select&nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]] ''Ser0''
 
::UID Byte 0
 
  
:[[Variable Types|BYTE]] ''Ser1''
+
===HaltA===
::UID Byte 1
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''HaltA'''
 +
|-
 +
| colspan="2" | Instructs a PICC in state ACTIVE(*) to go to state HALT&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]] ''Ser2''
 
::UID Byte 2
 
  
:[[Variable Types|BYTE]] ''Ser3''
+
===Initialise===
::UID Byte 3
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
 +
|-
 +
| colspan="2" | Initialises the RFID module ready for interaction with RFID tags.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
  
'''Return value'''
+
===IsNewCardPresent===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''IsNewCardPresent'''
 +
|-
 +
| colspan="2" | Is there a card present for us to communicate with.  Returns 0 for no card and 1 for valid card present.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:[[Variable Types|BYTE]]
 
  
 +
===MifareRead===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MifareRead'''
 +
|-
 +
| colspan="2" | Reads from a block of data on a MIFARE type tag&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | BlockAddress
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Buffer
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | BufferSize
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
===<span style="font-weight: normal;"><u><tt>AuthOff</tt></u></span>===
 
Resets the authentication allowing a new communications tasks to work.
 
  
'''Parameters'''
+
===MifareWrite===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''MifareWrite'''
 +
|-
 +
| colspan="2" | Writes to a block of data on a MIFARE type tag&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | BlockAddress
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Buffer
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | BufferSize
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
:''This macro has no parameters''
 
  
 +
===ReadCardSerial===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadCardSerial'''
 +
|-
 +
| colspan="2" | 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.&nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
'''Return value'''
 
  
:''This call does not return a value''
+
===ReadUIDByte===
 +
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadUIDByte'''
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | Index
 +
|-
 +
| colspan="2" | 0-9 = UID Data Bytes, 10 = UID Length, 11 = UID SAK&nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
  
===<span style="font-weight: normal;"><u><tt>AntennaOn</tt></u></span>===
+
===Select===
Switches on the RFID antenna.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 +
|-
 +
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 +
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Select'''
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" | ValidBits
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
 +
| width="90%" style="border-top: 2px solid #000;" | ''Return''
 +
|}
  
Called as part of the Initialise macro.
 
  
'''Parameters'''
+
===StopCrypto===
 
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
:''This macro has no parameters''
+
|-
 
+
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''StopCrypto'''
'''Return value'''
+
|-
 
+
| colspan="2" | 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.&nbsp;
:''This call does not return a value''
+
|-
 
+
|-
 
+
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
===<span style="font-weight: normal;"><u><tt>Compare</tt></u></span>===
+
| width="90%" style="border-top: 2px solid #000;" | ''Return''
Compares the read address from the Check macro with a fixed 5 bytes address.
+
|}
 
 
Returns 0 if the addresses match.
 
 
 
'''Parameters'''
 
 
 
:[[Variable Types|BYTE]] ''Add0''
 
 
 
:[[Variable Types|BYTE]] ''Add1''
 
 
 
:[[Variable Types|BYTE]] ''Add2''
 
 
 
:[[Variable Types|BYTE]] ''Add3''
 
 
 
:[[Variable Types|BYTE]] ''Add4''
 
 
 
 
 
'''Return value'''
 
 
 
:[[Variable Types|BYTE]]
 
 
 
 
 
===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>===
 
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''
 
 
 
 
 
===<span style="font-weight: normal;"><u><tt>Check</tt></u></span>===
 
Checks to see if a RFID tag is present.
 
 
 
Returns 255 if RFID tag responds to the request.
 
 
 
Returns 0 for no response.
 
 
 
'''Parameters'''
 
 
 
:''This macro has no parameters''
 
 
 
 
 
'''Return value'''
 
 
 
:[[Variable Types|BYTE]]
 
 
 
 
 
 
 
==Simulation macro reference==
 
 
 
''This component does not contain any simulation macros''
 
  
  
 
==Property reference==
 
==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 ''CHANNEL''.
+
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
 
+
|-
''<span style="color:red;">No additional information</span>''
+
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
 
+
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''  
 
+
|-
 
+
|-
<span style="font-weight: normal;"><u>MISO / SDI</u></span>
+
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
 
+
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Connections
This property is of type ''Single digital pin'' and can be referenced with the variable name ''MISO''.
+
|-
 
+
|-
SPI Data In Pin
+
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
 
+
| width="90%" | Channel
<span style="font-weight: normal;"><u>MOSI / SDO</u></span>
+
|-
 
+
| colspan="2" | SPI Channel selector&nbsp;
This property is of type ''Single digital pin'' and can be referenced with the variable name ''MOSI''.
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
SPI Data Out Pin
+
| width="90%" | Prescale
 
+
|-
<span style="font-weight: normal;"><u>SCK</u></span>
+
| colspan="2" | Prescale option selector&nbsp;
 
+
|-
This property is of type ''Single digital pin'' and can be referenced with the variable name ''CLK''.
+
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
 
+
| width="90%" | MOSI
SPI Serial Clock Pin
+
|-
 
+
| colspan="2" | SPI Data Out Pin SDO - Also Known as Master Out Slave In (MOSI) when used in Master mode.&nbsp;
<span style="font-weight: normal;"><u>SS</u></span>
+
|-
 
+
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
This property is of type ''Single digital pin'' and can be referenced with the variable name ''CS''.
+
| width="90%" | MISO
 
+
|-
SPI Chip Select Pin
+
| colspan="2" | SPI Data In Pin SDI - Also Known as Master In Slave Out (MISO) when used in Master mode.&nbsp;
 
+
|-
<span style="font-weight: normal;"><u>Reset</u></span>
+
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
 
+
| width="90%" | CLK
This property is of type ''Single digital pin'' and can be referenced with the variable name ''reset''.
+
|-
 
+
| colspan="2" | SPI Clock Pin CLK - The Clock signal is driven by the SPI master.&nbsp;
MFRC522 Reset Pin
+
|-
 +
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
 +
| width="90%" | CS / SS
 +
|-
 +
| colspan="2" | 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. &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
 +
| width="90%" | Reset
 +
|-
 +
| colspan="2" | MFRC522 Reset Pin &nbsp;
 +
|-
 +
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]]
 +
| width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Simulation
 +
|-
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]]
 +
| width="90%" | Label
 +
|-
 +
| colspan="2" | &nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
 +
| width="90%" | Scope Traces
 +
|-
 +
| colspan="2" | Selects if the scope traces are automatically generated or not&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
 +
| width="90%" | Console Data
 +
|-
 +
| colspan="2" | Selects if the console data is automatically generated or not&nbsp;
 +
|-
 +
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
 +
| width="90%" | API
 +
|-
 +
| colspan="2" | &nbsp;
 +
|}

Latest revision as of 13:11, 7 February 2023

Author Ben Rowland and STibor
Version 3.0
Category Wireless


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.

Component Source Code

Please click here to download the component source project: FC_Comp_Source_MFRC522.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_MFRC522.fcfx

Detailed description

No detailed description exists yet for this component

Examples

Here is a basic example program that reads the UID from a Mifare RFID tag and displays on an LCD. If the UID matches the UID stored in memory then a solenoid will fire allowing a door to be unlocked etc.

FC6 Icon.png Display UID


Here is a basic example program to read and modify data stored on a Mifare RFID tag.

FC6 Icon.png Read Write Test






Macro reference

AntennaOff

Fc9-comp-macro.png AntennaOff
Switches off the RFID antenna to save power. The antenna must be switched on again before communicating with an RFID tag. 
Fc9-void-icon.png - VOID Return


AntennaOn

Fc9-comp-macro.png AntennaOn
Switches on the RFID antenna. Called as part of the Initialise macro. 
Fc9-void-icon.png - VOID Return


Authenticate

Fc9-comp-macro.png 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. 
Fc9-u8-icon.png - BYTE Command
PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B 
Fc9-u8-icon.png - BYTE BlockAddress
The block number 
Fc9-u8-icon.png - BYTE Key
Crypteo key to use 
Fc9-u8-icon.png - BYTE Return


CompareUID

Fc9-comp-macro.png CompareUID
Compares the UID from the ReadCardSerial macro with 4 byte UID. Returns 0 if the addresses match. 
Fc9-u8-icon.png - BYTE Add0
 
Fc9-u8-icon.png - BYTE Add1
 
Fc9-u8-icon.png - BYTE Add2
 
Fc9-u8-icon.png - BYTE Add3
 
Fc9-u8-icon.png - BYTE Return


GetType

Fc9-comp-macro.png GetType
Translates the SAK (Select Acknowledge) to a PICC type 
Fc9-u8-icon.png - BYTE sak
The SAK byte returned from PICC_Select 
Fc9-u8-icon.png - BYTE Return


HaltA

Fc9-comp-macro.png HaltA
Instructs a PICC in state ACTIVE(*) to go to state HALT 
Fc9-u8-icon.png - BYTE Return


Initialise

Fc9-comp-macro.png Initialise
Initialises the RFID module ready for interaction with RFID tags. 
Fc9-void-icon.png - VOID Return


IsNewCardPresent

Fc9-comp-macro.png IsNewCardPresent
Is there a card present for us to communicate with. Returns 0 for no card and 1 for valid card present. 
Fc9-u8-icon.png - BYTE Return


MifareRead

Fc9-comp-macro.png MifareRead
Reads from a block of data on a MIFARE type tag 
Fc9-u8-icon.png - BYTE BlockAddress
 
Fc9-u8-icon.png - BYTE Buffer
 
Fc9-u8-icon.png - BYTE BufferSize
 
Fc9-u8-icon.png - BYTE Return


MifareWrite

Fc9-comp-macro.png MifareWrite
Writes to a block of data on a MIFARE type tag 
Fc9-u8-icon.png - BYTE BlockAddress
 
Fc9-u8-icon.png - BYTE Buffer
 
Fc9-u8-icon.png - BYTE BufferSize
 
Fc9-u8-icon.png - BYTE Return


ReadCardSerial

Fc9-comp-macro.png 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. 
Fc9-u8-icon.png - BYTE Return


ReadUIDByte

Fc9-comp-macro.png ReadUIDByte
 
Fc9-u8-icon.png - BYTE Index
0-9 = UID Data Bytes, 10 = UID Length, 11 = UID SAK 
Fc9-u8-icon.png - BYTE Return


Select

Fc9-comp-macro.png Select
 
Fc9-u8-icon.png - BYTE ValidBits
 
Fc9-u8-icon.png - BYTE Return


StopCrypto

Fc9-comp-macro.png 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. 
Fc9-void-icon.png - VOID Return


Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png Connections
Fc9-type-16-icon.png Channel
SPI Channel selector 
Fc9-type-16-icon.png Prescale
Prescale option selector 
Fc9-type-5-icon.png MOSI
SPI Data Out Pin SDO - Also Known as Master Out Slave In (MOSI) when used in Master mode. 
Fc9-type-5-icon.png MISO
SPI Data In Pin SDI - Also Known as Master In Slave Out (MISO) when used in Master mode. 
Fc9-type-5-icon.png CLK
SPI Clock Pin CLK - The Clock signal is driven by the SPI master. 
Fc9-type-5-icon.png CS / 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.  
Fc9-type-5-icon.png Reset
MFRC522 Reset Pin  
Fc9-conn-icon.png Simulation
Fc9-type-10-icon.png Label
 
Fc9-type-7-icon.png Scope Traces
Selects if the scope traces are automatically generated or not 
Fc9-type-7-icon.png Console Data
Selects if the console data is automatically generated or not 
Fc9-type-16-icon.png API