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

From Flowcode Help
Jump to navigationJump to search
(XML import BR)
(XML import)
Line 7: Line 7:
 
|-
 
|-
 
| width="20%" style="color: gray;" | Version
 
| width="20%" style="color: gray;" | Version
| 2.0 (Release)
+
| 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>WriteBlock</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>CompareUID</tt></u></span>===
Writes the contents of the 16-byte data buffer to the RFID block.
+
Compares the UID from the ReadCardSerial macro with 4 byte UID.
  
The data comes from the DataBuffer which can be set using the  
+
Returns 0 if the addresses match.
  
WriteDataBuffer macro.
+
'''Parameters'''
  
Returns 0 for a succesful write.
+
:[[Variable Types|BYTE]] ''Add0''
  
'''Parameters'''
+
:[[Variable Types|BYTE]] ''Add1''
 +
 
 +
:[[Variable Types|BYTE]] ''Add2''
  
:[[Variable Types|BYTE]] ''BlockAddress''
+
:[[Variable Types|BYTE]] ''Add3''
  
  
Line 49: Line 51:
  
  
===<span style="font-weight: normal;"><u><tt>ReadDataBuffer</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>IsNewCardPresent</tt></u></span>===
Reads a byte from the receive data buffer.
+
Is there a card present for us to communicate with.  
  
ID locations are 0-4
+
Returns 0 for no card and 1 for valid card present.
  
Data locations are 0-15
+
'''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]] ''Index''
+
:[[Variable Types|BYTE]] ''sak''
::Locations 0-15
+
::The SAK byte returned from PICC_Select
  
  
Line 82: Line 95:
  
  
===<span style="font-weight: normal;"><u><tt>ReadBlock</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>ReadCardSerial</tt></u></span>===
Reads the contents of the 16-byte data buffer block on the RFID.
+
Simple wrapper around PICC_Select.
  
The receive data is stored in the data buffer and read back using the ReadDataBuffer macro.
+
Returns true if a UID could be read.
  
Returns 0 for a succesful 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>SelectTag</tt></u></span>===
+
===<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]] ''Ser0''
+
:[[Variable Types|BYTE]] ''ValidBits''
  
:[[Variable Types|BYTE]] ''Ser1''
 
  
:[[Variable Types|BYTE]] ''Ser2''
+
'''Return value'''
 +
 
 +
:[[Variable Types|BYTE]]
 +
 
  
:[[Variable Types|BYTE]] ''Ser3''
+
===<span style="font-weight: normal;"><u><tt>StopCrypto</tt></u></span>===
 +
Used to exit the PCD from its authenticated state.
  
:[[Variable Types|BYTE]] ''Ser4''
+
Remember to call this function after communicating with an authenticated PICC - otherwise no new communications can start.
  
 +
'''Parameters'''
  
'''Return value'''
+
:''This macro has no parameters''
  
:[[Variable Types|BYTE]]
 
  
 +
'''Return value'''
  
===<span style="font-weight: normal;"><u><tt>WriteDataBuffer</tt></u></span>===
+
:''This call does not return a value''
Writes a value to the 16-byte data buffer
 
  
ID locations are 0-4
 
  
Data locations are 0-15
+
===<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]] ''Index''
+
:[[Variable Types|BYTE]] ''BlockAddress''
::0-15
+
 
 +
:[[Variable Types|BYTE]] ''Buffer''
  
:[[Variable Types|BYTE]] ''Data''
+
:[[Variable Types|BYTE]] ''BufferSize''
  
  
 
'''Return value'''
 
'''Return value'''
  
:''This call does not return a value''
+
:[[Variable Types|BYTE]]
  
  
===<span style="font-weight: normal;"><u><tt>Auth</tt></u></span>===
+
===<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]] ''AuthMode''
+
:[[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]] ''Key0''
+
:[[Variable Types|BYTE]] ''Key''
::Crypteo key to use - Byte 0
+
::Crypteo key to use
  
:[[Variable Types|BYTE]] ''Key1''
 
::Crypteo key to use - Byte 1
 
  
:[[Variable Types|BYTE]] ''Key2''
+
'''Return value'''
::Crypteo key to use - Byte 2
 
  
:[[Variable Types|BYTE]] ''Key3''
+
:[[Variable Types|BYTE]]
::Crypteo key to use - Byte 3
 
  
:[[Variable Types|BYTE]] ''Key4''
 
::Crypteo key to use - Byte 4
 
  
:[[Variable Types|BYTE]] ''Key5''
+
===<span style="font-weight: normal;"><u><tt>HaltA</tt></u></span>===
::Crypteo key to use - Byte 5
+
Instructs a PICC in state ACTIVE(*) to go to state HALT
  
:[[Variable Types|BYTE]] ''Ser0''
+
'''Parameters'''
::UID Byte 0
 
  
:[[Variable Types|BYTE]] ''Ser1''
+
:''This macro has no parameters''
::UID Byte 1
 
  
:[[Variable Types|BYTE]] ''Ser2''
 
::UID Byte 2
 
  
:[[Variable Types|BYTE]] ''Ser3''
+
'''Return value'''
::UID Byte 3
 
  
 +
:[[Variable Types|BYTE]]
  
'''Return value'''
 
  
:[[Variable Types|BYTE]]
+
===<span style="font-weight: normal;"><u><tt>ReadUIDByte</tt></u></span>===
 +
''<span style="color:red;">No additional information</span>''
  
  
===<span style="font-weight: normal;"><u><tt>AuthOff</tt></u></span>===
 
Resets the authentication allowing a new communications tasks to work.
 
  
 
'''Parameters'''
 
'''Parameters'''
  
:''This macro has no parameters''
+
:[[Variable Types|BYTE]] ''Index''
 +
::0-9 = UID Data Bytes, 10 = UID Length, 11 = UID SAK
  
  
 
'''Return value'''
 
'''Return value'''
  
:''This call does not return a value''
+
:[[Variable Types|BYTE]]
  
  
Line 221: Line 246:
  
  
===<span style="font-weight: normal;"><u><tt>Compare</tt></u></span>===
+
===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>===
Compares the read address from the Check macro with a fixed 5 bytes address.
+
Initialises the RFID module ready for interaction with RFID tags.
 
 
Returns 0 if the addresses match.
 
  
 
'''Parameters'''
 
'''Parameters'''
  
:[[Variable Types|BYTE]] ''Add0''
+
:''This macro has no parameters''
  
:[[Variable Types|BYTE]] ''Add1''
 
  
:[[Variable Types|BYTE]] ''Add2''
+
'''Return value'''
  
:[[Variable Types|BYTE]] ''Add3''
+
:''This call does not return a value''
  
:[[Variable Types|BYTE]] ''Add4''
 
  
  
'''Return value'''
+
==Simulation macro reference==
  
:[[Variable Types|BYTE]]
+
''This component does not contain any simulation macros''
  
  
===<span style="font-weight: normal;"><u><tt>Initialise</tt></u></span>===
+
==Property reference==
Initialises the RFID module ready for interaction with RFID tags.
+
<span style="font-weight: normal;"><u>Channel</u></span>
  
'''Parameters'''
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_spi::CHANNEL''.
  
:''This macro has no parameters''
+
SPI Channel selector
  
 +
<span style="font-weight: normal;"><u>Prescale</u></span>
  
'''Return value'''
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_spi::PR_SCALE''.
  
:''This call does not return a value''
+
Prescale option selector
  
 +
<span style="font-weight: normal;"><u>MOSI</u></span>
  
===<span style="font-weight: normal;"><u><tt>Check</tt></u></span>===
+
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_spi::MOSI''.
Checks to see if a RFID tag is present.
 
  
Returns 255 if RFID tag responds to the request.
+
SPI Data Out Pin SDO - Also Known as Master Out Slave In (MOSI) when used in Master mode.
  
Returns 0 for no response.
+
<span style="font-weight: normal;"><u>MISO</u></span>
  
'''Parameters'''
+
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_spi::MISO''.
  
:''This macro has no parameters''
+
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>
  
'''Return value'''
+
This property is of type ''Single digital pin'' and can be referenced with the variable name ''cal_spi::CLK''.
  
:[[Variable Types|BYTE]]
+
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''.
  
==Simulation macro reference==
+
Chip Select / Slave Select Pin
  
''This component does not contain any simulation macros''
+
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.
  
==Property reference==
+
<span style="font-weight: normal;"><u>Reset</u></span>
<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''.
+
This property is of type ''Single digital pin'' and can be referenced with the variable name ''reset''.
  
''<span style="color:red;">No additional information</span>''
+
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="font-weight: normal;"><u>MISO / SDI</u></span>
+
''<span style="color:red;">No additional information</span>''
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''MISO''.
 
  
SPI Data In Pin
 
  
<span style="font-weight: normal;"><u>MOSI / SDO</u></span>
+
<span style="font-weight: normal;"><u>Scope Traces</u></span>
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''MOSI''.
+
This property is of type ''True or false'' and can be referenced with the variable name ''cal_spi::ScopeTraces''.
  
SPI Data Out Pin
+
Selects if the scope traces are automatically generated or not
  
<span style="font-weight: normal;"><u>SCK</u></span>
+
<span style="font-weight: normal;"><u>Console Data</u></span>
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''CLK''.
+
This property is of type ''True or false'' and can be referenced with the variable name ''cal_spi::ConsoleData''.
  
SPI Serial Clock Pin
+
Selects if the console data is automatically generated or not
  
<span style="font-weight: normal;"><u>SS</u></span>
+
<span style="font-weight: normal;"><u>Injector</u></span>
  
This property is of type ''Single digital pin'' and can be referenced with the variable name ''CS''.
+
This property is of type ''Fixed list of ints'' and can be referenced with the variable name ''cal_spi::Injector''.
  
SPI Chip Select Pin
+
''<span style="color:red;">No additional information</span>''
 
 
<span style="font-weight: normal;"><u>Reset</u></span>
 
 
 
This property is of type ''Single digital pin'' and can be referenced with the variable name ''reset''.
 
 
 
MFRC522 Reset Pin
 

Revision as of 10:31, 9 May 2018


Author Ben Rowland and STibor
Version 3.0 (Release)
Category Wireless


Image 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. FC6 Icon.png 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

BYTE


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

BYTE


GetType

Translates the SAK (Select Acknowledge) to a PICC type

Parameters

BYTE sak
The SAK byte returned from PICC_Select


Return value

BYTE


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

BYTE


MifareWrite

Writes to a block of data on a MIFARE type tag

Parameters

BYTE BlockAddress
BYTE Buffer
BYTE BufferSize


Return value

BYTE


Select

No additional information


Parameters

BYTE ValidBits


Return value

BYTE


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

BYTE


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

BYTE


HaltA

Instructs a PICC in state ACTIVE(*) to go to state HALT

Parameters

This macro has no parameters


Return value

BYTE


ReadUIDByte

No additional information


Parameters

BYTE Index
0-9 = UID Data Bytes, 10 = UID Length, 11 = UID SAK


Return value

BYTE


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