Re: I2C SCL frequency 10% less than it should be at 400kHz
Posted: Wed Mar 29, 2017 4:33 pm
Well even with the latest patch I2C still doesn't work with PN532 boards. e.g ones like this
ESP32 Official Forum
https://esp32.com/
It doesn't work at all or has glitches? Does that device work with any other Arduino-type device you have?mvrhov wrote:Well even with the latest patch I2C still doesn't work with PN532 boards. e.g ones like this
Code: Select all
/**************************************************************************/
/*!
This example will attempt to connect to an ISO14443A
card or tag and retrieve some basic information about it
that can be used to determine what type of card it is.
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
To enable debug message, define DEBUG in PN532/PN532_debug.h
*/
/**************************************************************************/
#include <Wire.h>
#include <PN532_I2C.h>
#include "PN532.h"
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
void setup(void) {
Serial.begin(115200);
delay(10);
Serial.print("initializing i2c..");
Wire.begin(21,22,400000);
Serial.print("DONE\n");
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);
// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A card");
}
void loop(void) {
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.println("Found a card!");
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");
for (uint8_t i=0; i < uidLength; i++)
{
Serial.print(" 0x");Serial.print(uid[i], HEX);
}
Serial.println("");
// wait until the card is taken away
while (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength)) {}
}
else
{
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
}
Code: Select all
initializing i2c..DONE
write: 2
wait for ack at : 54
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
waiting for start (ACK): 0ACK not ready
Time out when waiting for ACK
Didn't find PN53x board
Code: Select all
initializing i2c..DONE
write: 2
wait for ack at : 49
ACK not ready
waiting for start (ACK): 1ready at : 50
Done reading
ACK OK
read (RSP):
and after a long time!!
Respponse fail -99Didn't find PN53x board
That Seeed-Studio repo you're based on is rather ancient... I just tried the Adafruit PN532 library (https://github.com/adafruit/Adafruit-PN532) and with a few small modifications examples/iso14443a_uid worked fine on both Particle and ESP32.mvrhov wrote:I've also tried it with a borrowed arduino Due and it also works.
Please update to the latest Arduino-ESP32 - a lot of changes went in today... this may improve things for you. Let us know how it goes!Hans Dorn wrote:I added an oled display and an arduino to my I2C setup to generate some traffic.
While testing some changes to make things faster I ran into issues with unreliable communication.
Errors will pop up several times a day, causing my reboot logic to trigger.