Using the IRQ line we can save the host controller from being blocked waiting for new cards. When a new card is detected, the PN532 will drive the IRQ to be low (It's usually high, see the PN532 user manual), which will let the host controller know it can try to read the detected card. This frees the host controller to do other things while waiting for new cards to be detected.
To implement this, I added a method for starting the card detection mode (startPassiveTargetIDDetection()) and another method for reading the detected card (readDetectedPassiveTargetID()). We need the PN532 to be connected using I2C and have the IRQ line connected to one of the pins in the host controller. The flow is like this:
Assuming the IRQ is connected to pin D2, when this pin is low then we know there's a card detected by the reader.
The host controller calls readDetectedPassiveTargetID() to read the card information.
Host controller can call startPassiveTargetIDDetection() again to start listening again for new cards.
I added readMifareClassicIrq.ino as a working example for this method. There's more documentation in the example, including a wiring diagram.
This code was tested with both Arduino Mega2560 and ESP32. The changes I made are adding a new functionality and aren't affecting any existing functionality. Everything is backward compatible. The new feature is only relevant in I2C mode, SPI or UART modes aren't affected.
I added this code because there's no clear example how to use the IRQ line, not in the official tutorial nor in any of the relevant discussion forums. I hope this helps others like me who struggled trying to get this behavior to work.
Using the IRQ line we can save the host controller from being blocked waiting for new cards. When a new card is detected, the PN532 will drive the IRQ to be low (It's usually high, see the PN532 user manual), which will let the host controller know it can try to read the detected card. This frees the host controller to do other things while waiting for new cards to be detected.
To implement this, I added a method for starting the card detection mode (startPassiveTargetIDDetection()) and another method for reading the detected card (readDetectedPassiveTargetID()). We need the PN532 to be connected using I2C and have the IRQ line connected to one of the pins in the host controller. The flow is like this:
I added readMifareClassicIrq.ino as a working example for this method. There's more documentation in the example, including a wiring diagram.
This code was tested with both Arduino Mega2560 and ESP32. The changes I made are adding a new functionality and aren't affecting any existing functionality. Everything is backward compatible. The new feature is only relevant in I2C mode, SPI or UART modes aren't affected.
I added this code because there's no clear example how to use the IRQ line, not in the official tutorial nor in any of the relevant discussion forums. I hope this helps others like me who struggled trying to get this behavior to work.