Better support for using the IRQ line in I2C - #82
Merged
Conversation
siddacious
suggested changes
Oct 31, 2020
siddacious
left a comment
Contributor
There was a problem hiding this comment.
@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 :)
https://github.com/adafruit/Adafruit-PN532#formatting-and-clang-format
…lso added an example for using it.
Author
|
Rebased + formatted the code using clang-format |
siddacious
approved these changes
Nov 23, 2020
Contributor
|
I'm going to go ahead and merge since the doxygen failures are for pre-existing code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.