Hello,
Hope you will be able to assist me with an issue I have.
First, my intention is to connect about 9 NFC antennas (I2C) using 2 multiplexers.
Using 2 analog multiplexers (1 to 16) with external power, what I’m actually trying to do is to mimic I2C communication to Arduino using the 2 outputs from each multiplexer.
Each antenna connected to the multiplexers in this way:
all SCL’s connected to mux1
all SDL’s connected to mux2
by changing the select lines I’m choosing a specific channel in both muxs, using pins A4,A5 to communicate with the specific antenna from the specific channel (I2C).
Using the code below, it seems that in some cases I’m getting response from each one of the antennas through the multiplexers, and in some other cases it seems that it get stuck or having a huge response time.
Will be happy to understand if my design is legit for my purpose, and if I’m using the code properly.
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>
PN532_I2C pn532_i2c(Wire);
PN532 nfc(pn532_i2c);
int pin_Out_S0 = 3;
int pin_Out_S1 = 5;
int pin_Out_S2 = 6;
int pin_Out_S3 = 9;
int antenaNum = 8;
void setup(void)
{
Serial.begin(115200);
pinMode(pin_Out_S0, OUTPUT);
pinMode(pin_Out_S1, OUTPUT);
pinMode(pin_Out_S2, OUTPUT);
pinMode(pin_Out_S3, OUTPUT);
uint32_t versiondata;
for (int i = 0; i < antenaNum; i++) {
Serial.print("setup start of antena ");
Serial.println(i);
switchMux(i);
delay(2500);
nfc.begin();
versiondata = nfc.getFirmwareVersion();
if (! versiondata)
{
Serial.println("Didn't find PN53x board");
}
else
{
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);
nfc.setPassiveActivationRetries(0x12);
nfc.SAMConfig();
delay(100);
}
Serial.println("---------------------------------------------");
}
}
void loop() {
Serial.println("Loop");
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength;
for (int i = 0 ; i < antenaNum; i++) {
switchMux(i);
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.print("---------Scan a NFC tag #");
Serial.print(i);
Serial.println(" -------");
Serial.println("Found a card!");
Serial.print("UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print("UID Value: ");
for (uint8_t c = 0; c < uidLength; c++)
{
Serial.print(" 0x"); Serial.print(uid[c], HEX);
}
Serial.println("");
delay(300);
}
}
}