-
Notifications
You must be signed in to change notification settings - Fork 180
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
Support Passive Mode #115
Support Passive Mode #115
Conversation
Hi! BTW does |
Good question, I found this referenced on a forum and went hunting through the datasheet to find the statement but couldn't. I've tried it with SPI and it works fine. On a related note, I've actually found the PN532 doesn't share any bus particularly will on the ESP32, in the end I just created a dedicated i2c bus for the PN532 in my project. |
I've made some tests and it looks like the default |
Ah, yes, I didn't answer that one. This is why I added the interrupt feature! The default behavior is to make a blocking read request, which is fairly expensive from a cycles perspective. This also broke my I2S playback, which can't tolerate a delay of more than 14ms. The interrupt feature puts the NFC into passive mode and waits for the IRQ pin to flag that a card is present, instead of checking every loop. Once the interrupt shows a card is present, you can make a read request. This removes the blocking nature! |
So, it also works for SPI connection? |
It does work with SPI. I haven't tried HSU, but I don't see why it wouldn't work. The delay is a timeout while waiting for a card - the default in the code is 1s. I thought it was a better solution to only call |
Oh, I've missed it - it was in the header file. |
In many projects it's desirable to support non-blocking code - instead of constantly checking to see if a card is present, put the PN532 into interrupt mode where it will tell the MCU when a card is detected. This allows the MCU to free up cycles and only read the card reader when a card has been detected.
Usage is simple, once the device is configured, simply call
startPassiveTargetIDDetection(PN532_MIFARE_ISO14443A)
and monitor the IRQ pin after setting it to input. It's also possible to useattachInterrupt()
(check for a FALLING pin)When a card is detected, the IRQ pin is pulled low by the PN532. At this point, read the card as usual. Once the read is complete, remember to call
startPassiveTargetIDDetection()
again.