adafruit / Adafruit_CircuitPython_PN532

CircuitPython driver for the PN532 NFC/RFID Breakout and PN532 NFC/RFID Shield
MIT License
93 stars 47 forks source link

More than one card detected! with no cards on reader #54

Closed PinkFreud closed 2 years ago

PinkFreud commented 2 years ago

With an itead pn532 reader connected to a Raspberry Pi via SPI and the default example script from https://learn.adafruit.com/adafruit-pn532-rfid-nfc/python-circuitpython configured for SPI, running the example would result in the error More than one card detected! being thrown.

Turning on debug, I see that reading from this device w/ no cards results in: Read frame: ['0x0', '0x0', '0xff', '0x3', '0xfd', '0xd5', '0x4b', '0x0', '0xe0', '0x0', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa', '0xaa']

In adafruit_pn532.py, the error is triggered by:

        if response is None:
            return None
        # Check only 1 card with up to a 7 byte UID is present.
        if response[0] != 0x01:
            raise RuntimeError("More than one card detected!")

Changing the first if to:

        if response is None or response[0] == 0x00:

appears to resolve the issue - adafruit_pn532.py no longer erroneously detects a response of '0' as > 1 card present.

PinkFreud commented 2 years ago

Never mind - this was my own problem. I had the pn532's pins configured incorrectly, but running an external libnfc-based util between runs of the script enabled the reader and left me chasing a red herring.

Configuring CS on D8 and RST on D17 for this reader works, without need to modify adafruit_pn532.py.