adafruit / Adafruit-PN532

Arduino library for SPI and I2C access to the PN532 RFID/Near Field Communication chip
Other
421 stars 265 forks source link

IRQ functionality not working as expected. #121

Closed mathaimon closed 7 months ago

mathaimon commented 8 months ago

Here is the video of the issue

caternuson commented 8 months ago

I think what is happening is when the card is already present when startListeningToNFC() is called, it gets read immediately (by the PN532) and the IRQ asserted, etc. - but all that action is not handled by the example code. At that point, the example logic is sort of wrapped around the axle and stuck in a loop.

Try this modified version of the startListeningToNFC() function in the readMifareClassicIrq example:

void startListeningToNFC() {
  // Reset our IRQ indicators
  irqPrev = irqCurr = HIGH;

  Serial.println("Starting passive read for an ISO14443A Card ...");
  if (!nfc.startPassiveTargetIDDetection(PN532_MIFARE_ISO14443A)) {
    Serial.println("No card found. Waiting...");
  } else {
    Serial.println("Card already present.");
    handleCardDetected();    
  }
}
mathaimon commented 8 months ago

The above change seems to fix the issue.

caternuson commented 8 months ago

OK, the example has been updated.

But hopefully it also shows the general behavior, so you won't run into a similar issue if you start adapting that example. The call to startPassiveTargetIDDetection() will actually also read any NFC that is also present. So be sure to check it's return and add logic and other calls as needed. That's really all that was done to fix the example.

mathaimon commented 7 months ago

Can this issue be closed now