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

Support Passive Mode #115

Merged
merged 1 commit into from
Jul 5, 2021
Merged

Conversation

gilphilbert
Copy link

@gilphilbert gilphilbert commented Jul 5, 2021

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 use attachInterrupt() (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.

@Pillar1989 Pillar1989 merged commit fa65453 into Seeed-Studio:arduino Jul 5, 2021
@mrdc
Copy link

mrdc commented Sep 21, 2021

@gilphilbert

Hi!
Note: The PN532 only supports use of the IRQ pin in I2C mode
Any workaround for HSU or SPI connections? ESP32 has issues with PN532 when I2C is used...

BTW does readPassiveTargetID(PN532_MIFARE_ISO14443A); constantly checks for a card blocking the code?

@gilphilbert
Copy link
Author

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.

@mrdc
Copy link

mrdc commented Sep 23, 2021

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.

I've made some tests and it looks like the default readPassiveTargetID(PN532_MIFARE_ISO14443A,,) always brings ~1 sec delay when called in the loop, when no cards are present (blocks other tasks). When there is a card being read there is no delay in the loop execution.

@gilphilbert
Copy link
Author

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!

@mrdc
Copy link

mrdc commented Sep 24, 2021

Once the interrupt shows a card is present, you can make a read request.
Thanks, good solution.

Note: The PN532 only supports use of the IRQ pin in I2C mode

I've tried it with SPI and it works fine.

So, it also works for SPI connection?

@gilphilbert
Copy link
Author

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 readPassiveTargetID(...) when there's a card actually present.

@mrdc
Copy link

mrdc commented Sep 24, 2021

the default in the code is 1s

Oh, I've missed it - it was in the header file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants