MFRC522 RFID reader
The blue RC522 board with the antenna coil printed round its edge, and the cards that come in the bag with it. It reads 13.56 MHz cards and key fobs over SPI.
Aliases: RFID reader, RC522, NFC reader.
Beside the board on the canvas are the cards. Tap one to lay it on the reader and tap it again to take it off. Only one card is on the antenna at a time.
Pins
| Pin | What it does |
|---|---|
SDA |
Chip select for SPI (the name comes from the chip's I2C mode). |
SCK |
SPI clock. |
MOSI |
SPI data in. |
MISO |
SPI data out, at 3.3 V. |
IRQ |
Interrupt out; most sketches leave it unwired. |
GND |
Ground. |
RST |
Low holds the chip in power-down. Pulled up on the board. |
3.3V |
Supply. 3.3 V, not 5 V. |
On an Uno: SDA to 10, SCK to 13, MOSI to 11, MISO to 12, RST to 9, as
every tutorial wires it.
Properties
uids lists up to four cards, each as hex bytes, separated by commas. A card with a
four-byte UID is a MIFARE Classic 1K; one with seven bytes is an NTAG213 sticker.
What is modeled
The chip is its datasheet: 64 registers over SPI, the 64-byte FIFO, the CRC
coprocessor, the timer that gives up on a silent card after 25 ms, the version
register reading 0x92. The cards answer as ISO/IEC 14443-3 cards do: REQA, the
anticollision loop and SELECT at one or two cascade levels, and HLTA. A halted
card stays quiet until it leaves the field, so a sketch that calls PICC_HaltA()
reads each tap once.
A MIFARE Classic has 64 blocks of 16 bytes behind two keys per sector, all
FF FF FF FF FF FF as delivered. Authenticate with the right key and MIFARE_Read
and MIFARE_Write work on that sector; the wrong key times out, as it does on a
real card. What a sketch writes stays on the card for the rest of the run. An
NTAG213 has 45 pages of 4 bytes and needs no key.
MFRC522.h has the calls the tutorials use: PCD_Init, PICC_IsNewCardPresent,
PICC_ReadCardSerial, uid, PICC_HaltA, PCD_Authenticate, MIFARE_Read,
MIFARE_Write, PICC_GetType, PCD_DumpVersionToSerial and the dumps.
What is not modeled
The radio: range, field strength, and a second card in the field colliding with the first. Crypto1, because the chip does it internally and a sketch only ever sees plaintext. The access bits are stored but not enforced (except that key A reads back as zeros), and value blocks are refused. The self test only checks the version. Reading every register costs a little time, as SPI does here: a card read takes a few tens of milliseconds on an Uno.