Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for using the IRQ line in I2C #82

merged 2 commits into from Nov 23, 2020


Copy link

@Udinic Udinic commented Sep 24, 2020

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:

  1. Host controller calls startPassiveTargetIDDetection()
  2. Assuming the IRQ is connected to pin D2, when this pin is low then we know there's a card detected by the reader.
  3. The host controller calls readDetectedPassiveTargetID() to read the card information.
  4. 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.

Copy link

@siddacious siddacious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Udinic It looks like the clang-format check is failing; please take a look at the info in the README to get it passing. Thanks :)

Copy link

Udinic commented Nov 1, 2020

Rebased + formatted the code using clang-format

Copy link

I'm going to go ahead and merge since the doxygen failures are for pre-existing code

@siddacious siddacious merged commit bee37dd into adafruit:master Nov 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants