PN532 NFC reader

The red PN532 NFC module V3, with a white card, a blue key fob, another card and an NTAG213 sticker beside it to tap. Adafruit_PN532.h drives it.

Aliases: PN532, NFC module, NFC RFID reader, Elechouse PN532 V3.

Tap a card to lay it on the antenna; tap it again to take it off. Only one card is on the reader at a time.

Pins

Pin What it does
VCC Supply, 3.3 to 5 V (the board has its own regulator).
GND Ground.
SDA, SCL I2C, at address 0x24, with pull-ups on the board.
IRQ Low while the chip has an answer ready. Optional over I2C.
RST Reset, active low, pulled up on the board. Optional.
SCK, MISO, MOSI, SS SPI, least significant bit first.

Properties

mode is where the board's two little switches are set: I2C or SPI. The sketch has to match it: Adafruit_PN532 nfc(IRQ, RESET) is I2C, Adafruit_PN532 nfc(SS) is hardware SPI and Adafruit_PN532 nfc(SCK, MISO, MOSI, SS) software SPI.

uids lists the cards, four or seven hex bytes each, separated by commas. A four-byte UID is a MIFARE Classic 1K, a seven-byte one an NTAG213.

What the model gets right

The chip speaks in frames, as NXP's PN532 user manual lays out: the host sends a command frame, the chip answers with an ACK a millisecond later and then with the answer, and pulls IRQ low while it has something to read. Over I2C each read starts with the status byte the manual describes.

The commands the libraries send. GetFirmwareVersion says PN532, version 1.6. SAMConfiguration, RFConfiguration and SetParameters are accepted. InListPassiveTarget finds the card on the reader and gives its ATQA, SAK and UID; with no card it waits, forever by default, or for setPassiveActivationRetries tries. A card tapped while it waits is found at once. InDataExchange reads and writes MIFARE Classic blocks behind their keys (every sector starts with FF FF FF FF FF FF) and NTAG213 pages, with the same card model as the MFRC522.

So the Adafruit examples readMifare, readMifareClassic, iso14443a_uid and the NTAG ones run as they stand, and readPassiveTargetID waits for a tap.

What it does not model

The radio: no range, no second card in the field, no collision. FeliCa, ISO 14443-4 (DESFire cards and phones), card emulation and peer to peer, and the HSU (serial) mode are not modeled either.

Common mistakes

The board's switches. A sketch for I2C on a board switched to SPI finds no PN532.

Expecting readPassiveTargetID to return when there is no card: with its default timeout it waits until one is tapped.