Hello,
I got an RC522 RFID reader that work on SPI communication.I implement 4 of them on a protype board.With the same electrical circuit if use a code that active only one antenna at the time it's working.However if i active all of them in the same time (same circuit) only one is working ( the number 2) so i wondering what i am doing wrong.
Thanks for any guidance,my code is bellow
-
- Reset 9 5 RST
- SPI SS 10 53 SDA
- SPI MOSI 11 51 MOSI
- SPI MISO 12 50 MISO
- SPI SCK 13 52 SCK
- The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS1_PIN 10
#define RST1_PIN 9
#define SS2_PIN 7
#define RST2_PIN 8
#define SS3_PIN 5
#define RST3_PIN 6
#define SS4_PIN 3
#define RST4_PIN 4
MFRC522 mfrc522_1(SS1_PIN, RST1_PIN); // Create MFRC522 instance.
MFRC522 mfrc522_2(SS2_PIN, RST2_PIN);
MFRC522 mfrc522_3(SS3_PIN, RST3_PIN);
MFRC522 mfrc522_4(SS4_PIN, RST4_PIN);
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522_1.PCD_Init(); // Init MFRC522 card
mfrc522_2.PCD_Init();
mfrc522_3.PCD_Init();
mfrc522_4.PCD_Init();
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( !mfrc522_1.PICC_IsNewCardPresent()&& !mfrc522_2.PICC_IsNewCardPresent()&& !mfrc522_3.PICC_IsNewCardPresent()&& !mfrc522_4.PICC_IsNewCardPresent()
) {
return;
}
// Select one of the cards
if ( !mfrc522_1.PICC_ReadCardSerial()&&! mfrc522_2.PICC_ReadCardSerial()&&! mfrc522_3.PICC_ReadCardSerial()&&! mfrc522_3.PICC_ReadCardSerial()) {
return;
}
Serial.print(F("<card_uid>"));
dump_byte_array(mfrc522_1.uid.uidByte, mfrc522_1.uid.size);
Serial.print(F("</card_uid><gate_uid>1</gate_uid>"));
Serial.print(F("<card_uid>"));
dump_byte_array(mfrc522_2.uid.uidByte, mfrc522_2.uid.size);
Serial.print(F("</card_uid><gate_uid>2</gate_uid>"));
Serial.print(F("<card_uid>"));
dump_byte_array(mfrc522_3.uid.uidByte, mfrc522_3.uid.size);
Serial.print(F("</card_uid><gate_uid>3</gate_uid>"));
Serial.print(F("<card_uid>"));
dump_byte_array(mfrc522_4.uid.uidByte, mfrc522_4.uid.size);
Serial.print(F("</card_uid><gate_uid>4</gate_uid>"));
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522_1.PICC_DumpToSerial(&(mfrc522_1.uid));
delay(100);
}
void dump_byte_array(byte buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer < 0x10 ? " 0" : " ");
_ Serial.print(buffer, HEX);_
_ }_
_}*_