Component: RFID (MFRC522) (Wireless)

From Flowcode Help
Jump to navigationJump to search


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 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

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