adafruit / Adafruit-PN532

Arduino library for SPI and I2C access to the PN532 RFID/Near Field Communication chip
Other
419 stars 265 forks source link

No ACK Frame on ESP32 + SPI, hangs after first tag read or no tag reads (With solution) #117

Open PockyBum522 opened 1 year ago

PockyBum522 commented 1 year ago

I was using known working code, and suddenly, after a few days of things working properly, I started getting no tag reads whatsoever when setting setPassiveActivationRetries(0x01); in the iso14443a_uid example.

Alternate behavior observed: It would read the tag once fine, then hang on the next readPassiveTargetID(); after a tag was read.

I enabled some of the debugs in the library, and saw there was NO ACK FRAME messages when it tried to send data to the PN532.

I made changes in Adafruit_PN532.cpp:

Under line 335 where it says // I2C TUNING I changed this on line 336:

delay(SLOWDOWN); (Original line in 1.3.1)

to delay(1); (My modification.)

This means a delay of 1ms no matter what interface you're using. I'm using SPI. Before the modification, the library would only delay if you're using i2c. This fixed my issue.

I have board v1.3, I am using library 1.3.1. I see this behavior on two separate Adafruit PN532 boards. Both 1.3. This fixed the issue on both of them. I'm using a ESP32-S3-DevKitC-1 with both boards (Not the same one, this issue exists on two independent adafruit boards with a different ESP32-S3-DevKitC-1 on each.

The weirdest part is it WAS WORKING on one of the setups without the delay a few days ago, and was working solidly for a few days so it wasn't a fluke. I'm guessing the PN532 is just on the hairy edge of responding fast enough.

Let me know if I should pull request this, I'd be happy to. I have tested it with the iso14443a_uid example with and without the library modifications several times. It reliably breaks/fixes things when I remove/add that delay(1);

PockyBum522 commented 1 year ago

If it ends up mattering, pins used are:

define PN532_SS 5

define PN532_SCK 6

define PN532_MOSI 7

define PN532_MISO 8

OguzCiftci commented 10 months ago

Sir, you are a lifesaver ❤️

MaxMyzer commented 4 months ago

Hello,

Just wanted to add this is not exclusive to ESP32, I was able to reproduce it on an Arduino RP2040 Connect.