Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By beic
#83386 Hi there,

I struggling with my setup over two weeks now, I can't make my WeMos D1 mini and PN532 RFID on I2C to work constantly and stable.

I have bought PN532 RFID v3 Module and I hooked and setup to work over I2C.

Image

In 85% it will give me "Didn't find PN53x board" message and exception error:

Code: Select allSoft WDT reset

ctx: cont
sp: 3ffef460 end: 3ffef640 offset: 01b0

>>>stack>>>
3ffef610:  3fffdad0 3ffee394 3ffee5f4 40202178 
3ffef620:  3fffdad0 00000000 3ffee610 40203058 
3ffef630:  feefeffe feefeffe 3ffee620 40100114 
<<<stack<<<


Image

or it will freeze the entire I2C bus on restart or after uploading the Sketch with infinite loop.

I'm using Arduino IDE 1.8.2 and ESP8266 Arduino Core 2.3.0.

Libraries what I'm using/tried:
https://github.com/adafruit/Adafruit-PN532
https://github.com/elechouse/PN532

Sketch what I'm using:

Code: Select all#include "Wire.h"
#include "PN532_I2C.h"
#include "PN532.h"

PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);

String userRFID = "";

void setup(void)
{

  Serial.begin(9600);
  Serial.println("NFC/RFID Reader");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);

  //  Non-blocking procedure
  nfc.setPassiveActivationRetries(0x01);
 
  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("Waiting for an ISO14443A Card ...");
}


void loop()
{
  readRFID();
}

void readRFID(void)
{
  boolean success;
  uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};
  uint8_t uidLength;

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

  if (success)
  {
    for (uint8_t i = 0; i < uidLength; i++)
    {
      if (uid[i] <= 0xF) {
        userRFID += "0";
      }
      userRFID += String(uid[i] & 0xFF, HEX);
    }
    userRFID.toUpperCase();
    Serial.println(userRFID);
    delay(400);
    userRFID = "";
  }
}


Just to mention, I'm only using 4 wires, 2 for Power and 2 for I2C bus, 20cm Dupont cable.
The DIP switch/selector is set correctly 1:On and 2:Off.

Also mentionable that I have way more better results on Uno and Mega Dev boards.

Any suggestion or help would be greatly appreciated!

Thank you!
User avatar
By QuickFix
#83388 The soft reset is coming from the "while (1); // halt" and maybe also the following exception.
Change it into an actual Halt (while (1) { yield() };") to see if the exception disappears.

The Adafruit library only supports SPI on the ESP (not I2C) and the elechouse library doesn't mention the ESP, so one has to assume no support. :idea:
Are you using a stable power supply able to deliver enough current?
On what voltage are you powering the PN532 board: 3.3V or 5V?
If 5V how did you connect the I2C lines to the ESP: the I2C and UART interfaces of the PN532 are 5V, only SPI can work on both 3.3V and 5V.

Just some thoughts. ;)
User avatar
By beic
#83389
QuickFix wrote:The soft reset is coming from the "while (1); // halt" and maybe also the following exception.
Change it into an actual Halt (while (1) { yield() };") to see if the exception disappears.

The Adafruit library only supports SPI on the ESP (not I2C) and the elechouse library doesn't mention the ESP, so one has to assume no support. :idea:
Are you using a stable power supply able to deliver enough current?
On what voltage are you powering the PN532 board: 3.3V or 5V?
If 5V how did you connect the I2C lines to the ESP: the I2C and UART interfaces of the PN532 are 5V, only SPI can work on both 3.3V and 5V.

Just some thoughts. ;)


Thank you for your quick repose QuickFix!

1. Just read on Adafruit forum, "It only works in SPI mode. The ESP8266 doesn't handle I2C clock stretching, which the PN532 uses.", neverless, it's working 50/50% on I2C (same case with elechouse library) :lol:

2. For Power, I'm using from PC's USB port (with Serial Upload) and from another USB port soldered to 5V pin on the WeMos D1 mini module.

3. Driving PN532 module on 5V

4. I connected I2C directly, didn't used any level shifter nor pull-up resistors (PN532 board doesn't has pull-ups onboard)

Now, after a while, I connected PN532 module over SPI and 3.3V, tried both libraries and how I see it's working without any issue for now.

My second concern now will be the PN532 Board, MicroSD Card and the Buzzer Shield, because now they would use all the same D5 (SCK) pin.