Hello,
I'm trying to use 4 PN532 in SPI.
When there is only one reader it read all the times, but when the 4 are active only 1 of them can read.
Here's my code, I tried forcing SS pin LOW and HIGH but none of the readers can read after that.
Do you have any idea of what causing this ?
#include <SPI.h>
#include <Adafruit_PN532.h>
#define SCK 13
#define MOSI 11
#define MISO 12
/*pins de selection d'esclave*/
#define SS_1_PIN 5
#define SS_2_PIN 4
#define SS_3_PIN 9
#define SS_4_PIN 8
/*tableau des pins de selection d'esclave*/
byte ssPins[] = { SS_1_PIN, SS_2_PIN, SS_3_PIN, SS_4_PIN };
/*nombre de lecteur RFID*/
#define NB_OF_READERS 4
Adafruit_PN532 nfc1(SCK, MISO, MOSI, SS_1_PIN);
Adafruit_PN532 nfc2(SCK, MISO, MOSI, SS_2_PIN);
Adafruit_PN532 nfc3(SCK, MISO, MOSI, SS_3_PIN);
Adafruit_PN532 nfc4(SCK, MISO, MOSI, SS_4_PIN);
Adafruit_PN532 nfcs[] = { nfc1, nfc2, nfc3, nfc4 };
void setup(void) {
Serial.begin(115200);
Serial.println("Hello!");
//bloquer toute communication des lecteurs RFID
for (byte ssPin = 0; ssPin < NB_OF_READERS; ssPin++) {
pinMode(ssPins[ssPin], OUTPUT);
digitalWrite(ssPins[ssPin], HIGH);
}
for (byte reader = 0; reader < NB_OF_READERS; reader++) {
digitalWrite(ssPins[reader], LOW);
nfcs[reader].begin();
uint32_t versiondata = nfcs[reader].getFirmwareVersion();
if (!versiondata) {
Serial.print("Didn't find PN53x board");
while (1)
;
}
Serial.print("Found chip PN5");
Serial.println((versiondata >> 24) & 0xFF, HEX);
nfcs[reader].SAMConfig();
digitalWrite(ssPins[reader], HIGH);
}
Serial.println("Waiting for an ISO14443A Card ...");
}
uint8_t 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)
void loop(void) {
for (int i = 0; i < NB_OF_READERS; i++) {
success = nfcs[i].readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength, 100);
Serial.print(i);
Serial.print(" : ");
if (success) {
for (int l = 0; l < uidLength; l++) {
Serial.print(uid[l] < 0x10 ? "0" : "");
Serial.print(uid[l], HEX);
}
Serial.println("");
} else {
Serial.println("Impossible");
}
Serial.println("");
delay(10);
}
}

