I am working on a project that involves 3 PN532_modules to an ESP32, which sends the Tag_ID over BLE. Plan A was to use One module on i2c_1, second on I2C_2 and third over SPI.
The SPI one works as expected. Though I am having issues with using 2 I2c Buses using the same Adafruit Library. Exact issues are-
- Unreliable reading while using 2 different i2c buses
- Sometimes the SPI bus freezes after scanning a Tag on one of i2c connected readers. My code is here
#include <Arduino.h>
#include <Wire.h>
//#include <Adafruit_PN532_2.h>
#include <Adafruit_PN532.h>
#define SDA_1 (21)
#define SCL_1 (22)
#define SDA_2 (33)
#define SCL_2 (32)
Adafruit_PN531 nfc1(SDA_1, SCL_1);
Adafruit_PN532 nfc2(SDA_2, SCL_2);
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println("Serial ready");
nfc1.begin();
nfc2.begin();
uint32_t versiondata_1 = nfc1.getFirmwareVersion();
if (! versiondata_1) {
while (1); // halt
}
Serial.println(versiondata_1);
uint32_t versiondata_2 = nfc2.getFirmwareVersion();
if (! versiondata_2) {
while (1); // halt
}
Serial.println(versiondata_2);
}
void loop(void) {
uint8_t success_1;
uint8_t uid_1[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength_1; // Length of the UID (4 or 7 bytes
uint8_t success_2;
uint8_t uid_2[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength_2; // Length of the UID (4 or 7 bytes
success_1 = nfc1.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid_1, &uidLength_1);
delay(10);
success_2 = nfc2.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid_2, &uidLength_2);
delay(10);
if (success_1)
{
Serial.println(success_1);
Serial.print(" UID_1 Value: ");
nfc1.PrintHex(uid_1, uidLength_1);
Serial.println("");
}
delay(10);
if (success_2)
{
Serial.print(" UID_2 Value: ");
nfc2.PrintHex(uid_2, uidLength_2);
Serial.println("");
}
delay(10);
}