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

User avatar
By beic
#83392
btidey wrote:If you wanted to use i2c it mIght be worth trying the brzo i2c library.

https://github.com/pasko-zh/brzo_i2c

You have to use external pull up resistors with i2c. Internal pull ups on esp are not low enough value.


Thank you, I already saw that a few days ago, but for that I need more brain power to write a custom library for the PN532 chip.
User avatar
By StanJ
#84517 The current Arduino ESP I2C library (v2.6.0 via Board Manager) DOES support clock stretching on any bits; I've tested that pretty thoroughly before they released 2.6.0. I don't know offhand what the stretch requirements are for your RFID part, but you can set the stretch UP from it's default 230us to around 5ms before you start to have problems. If you go over ~25ms the WiFi may disconnect. There's a fix in the works for that, but it's not out yet.

To change the stretch limit, add
Wire.setClockStretchLimit(time in microseconds);
immediately after the Wire.begin(); statement.

edit: I just looked up your part: max clock stretch on page 211 is 1ms, so that 'time in microseconds' above is 1000.
You won't have to worry about the 25ms problem, as you're only stretching 1/25th of that pre-2.6.0 limit. With the current (as of a few days ago) ESP8266 library, Adafruit can happily include I2C support if they so choose.
Last edited by StanJ on Thu Jan 30, 2020 7:11 am, edited 1 time in total.
User avatar
By mahasiswa1
#86733
beic wrote: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!



sorry can you share the code and wire? i have same problem with that in my final college project :( and im very confused about what happen. Thanks a lot and God Bless