RFID & NFC · lesson 3 of 8
Two cards at once: anticollision
Lay the card and the tag on the reader together. Both answer at the same instant, bit by bit, and where their UIDs differ the reader hears a collision. Anticollision walks down the bits like a binary tree: pick a branch, ask again with that prefix, select the card that's left, halt it, repeat until nobody answers.
Find both cards at once, and point to the exact bit where their UIDs collided.
You're done when
inventorylists 2 cards with both UIDs.- It names the collision bit, and the walk-through above lands on the same bit with your two UIDs.
On the board
You will learn
- bit collisions
- binary tree walk
- NVB
- BCC
- cascade levels
- SAK
- HALT · WUPA
uv run pio run -d labs/rfid-lab-r3 -e rfid-lab-r3 -t uploadParts required
Parts library- ESP32-S3-DevKitC-1 + USB-C data cable
- 1.9″ ST7789 screen
- RC522 card reader
- MIFARE card and key fob
Anticollision: a walk down the bits
The two rows are the UID bits of two cards, in the order they travel (least significant bit of byte 0 first). Step through: where the bits differ the reader hears a collision, picks 1, and only the matching card keeps answering. Type your own UIDs from the monitor.
Interactive binary tree walkthrough of ISO14443-A anticollision resolving two RFID cards in the same RF field. The two rows are the UID bits of two cards, in the order they travel (least significant bit of byte 0 first). Step through: where the bits differ the reader hears a collision, picks 1, and only the matching card keeps answering. Type your own UIDs from the monitor.
- Key concepts: bit collisions, binary tree walk, NVB, BCC, cascade levels, SAK, HALT · WUPA.
- Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).
Interactive diagram loads after page initialization.
What the screen shows
The board's screen has six views. A click on the push button (or BOOT) goes to the next one, a double-click runs the action written at the bottom left, a long press pauses card polling. Pick a view to see what each part means; the numbers match the list below it.
Gallery of ST7789 display screens rendered during the RC522 RFID labs. The board's screen has six views. A click on the push button (or BOOT) goes to the next one, a double-click runs the action written at the bottom left, a long press pauses card polling. Pick a view to see what each part means; the numbers match the list below it.
- Key concepts: bit collisions, binary tree walk, NVB, BCC, cascade levels, SAK, HALT · WUPA.
- Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).
Interactive diagram loads after page initialization.
Commands, in order
Type these in the serial monitor (uv run pio device monitor) unless the grey tag says otherwise. The coloured tag says what should be near the board while it runs.
uv run pio run -d labs/rfid-lab-r3 -e rfid-lab-r3 -t uploadMac terminalcard: doesn't matter- Does
- Flashes lab R3's own firmware: everything from R2, plus inventory (and a double-click on the card view runs it).
helplists exactly this lab's commands. - You should see
rfid-lab-r3: reader task started, then this lab's command list and views.- If not
- “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
lay the card and the tag togetherwith your handscard + tag together- Does
- Both cards wake on the same WUPA. The poll resolves the collision and selects one of them.
- You should see
- The card view shows one UID (always the same one) and an amber line:
collision at bit 23(your bit will differ). - If not
- Only one card found? Overlap them more: both must sit inside the antenna's loop.
inventory (or double-click on the card view)serial monitorcard + tag together- Does
- Switches the field off for 10 ms so every card restarts, then REQA → select → halt, again and again until nobody answers.
- You should see
#1 9C:4F:6A:0D … collision at level 1 bit 23 -> chose 1,#2 9C:4F:2A:1B …, theninventory: 2 cards in the field.- If not
select failed (collision): move the cards a little and run it again.
inventory with one card, then noneserial monitorcard on, then move it- Does
- Same walk, nothing to resolve.
- You should see
1 cardwithout a collision line, then0 cards.
Steps
0 of 6 ticked. Ticks are saved in this browser.
Bits travel least-significant first, so “bit 23” is bit 6 of the third UID byte. Our driver is tested for two cards at once: with three or more, the chip's collision position after the first branch is harder to trust. 7-byte UIDs take two cascade levels; the first part starts with 88h, the cascade tag.
Preview: what you should see
Interactive RC522 13.56 MHz RFID reader simulator showing tag detection, VersionReg 0x92, UIDs, and serial monitor logs.
- Key concepts: bit collisions, binary tree walk, NVB, BCC, cascade levels, SAK, HALT · WUPA.
- Signals & pins: 3V3 (VCC), 3V3 (RC 3.3V), GPIO7 (BLK), GPIO8 (RES), GPIO9 (DC).
Interactive diagram loads after page initialization.
ESP32-S3 peripherals used in this lab
Open interactive GPIO pinoutExplore the hardware blocks, pin rules, and registers behind this experiment.
- GPIO and IO MUX
45 pins, and a matrix that routes almost any signal to almost any pin
- SPI
Fast four-wire bus for screens, card readers and flash
- UART
Three serial ports, the one you see in the serial monitor
- CPU
Two Xtensa LX7 cores at up to 240 MHz
- SRAM
512 KB of fast on-chip RAM for your code and data
- ROM
384 KB of factory code: the bootloader and download mode
Troubleshooting & hardware gotchas
See all 17 ESP32-S3 hardware gotchas- What if it does not work or behaves unexpectedly?
- Bits travel least-significant first, so “bit 23” is bit 6 of the third UID byte. Our driver is tested for two cards at once: with three or more, the chip's collision position after the first branch is harder to trust. 7-byte UIDs take two cascade levels; the first part starts with 88h, the cascade tag.
- If “uv run pio run -d labs/rfid-lab-r3 -e rfid-lab-r3 -t upload” does not work
- “Failed to connect”: hold BOOT, tap RST, release BOOT, run it again.
- If “lay the card and the tag together” does not work
- Only one card found? Overlap them more: both must sit inside the antenna's loop.
- If “inventory (or double-click on the card view)” does not work
select failed (collision): move the cards a little and run it again.- Four pins are read at reset
- GPIO0, GPIO3, GPIO45 and GPIO46 are sampled the moment the chip comes out of reset: they pick the boot mode, the flash voltage, the ROM log and the JTAG source. Anything wired to them must not pull them the wrong way at power-up. After reset they are normal pins again.
- GPIO3 has no pull resistor at reset
- GPIO0 has a weak pull-up and GPIO45/46 weak pull-downs, but GPIO3 floats. When the eFuses make it choose the JTAG source, an outside circuit has to hold it at a clear level.
- GPIO47 and 48 run at 1.8 V on R16V modules
- Modules with the ESP32-S3R16V chip set the flash voltage to 1.8 V, and GPIO47/48 share that supply. A 3.3 V part on those pins sees the wrong levels.
- The pins are not 5 V tolerant
- A high input may go up to the pin's supply plus 0.3 V, so about 3.6 V on a 3.3 V board, and the power pins are rated to 3.6 V at most. 5 V from a sensor or an Arduino can damage the chip: use a level shifter or a divider.