adafruit / Adafruit_CircuitPython_PN532

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

PN532_SPI._wait_ready cannot recover if failing #28

Closed basil-huber closed 4 years ago

basil-huber commented 4 years ago

PN532_SPI._wait_ready polls the status until ready. However, the command to be sent is overwritten by the response received. Hence, if the device is not ready at the first request, we might send the wrong command for subsequent polling:

while (time.monotonic() - timestamp) < timeout:
                time.sleep(0.02)   # required
                spi.write_readinto(status, status) #pylint: disable=no-member
                if reverse_bit(status[1]) == 0x01:  # LSB data is read in MSB
                    return True      # Not busy anymore!
                else:
                    time.sleep(0.01)  # pause a bit till we ask again

the command in status is overwritten.