Multiple RC522 on an SPI bus won't work

Hello everyone,

I'm trying to build a project using multiple RFID reader.
I need to read 7 different chips simultaneously to detect different patern that I would then send to a raspberry pie to display the correct result on a screen.

I've tried setting up a proof of concept with only 4 reader, but I'm running into some diffculty.

I'm using some RC522 reader with this library: GitHub - miguelbalboa/rfid: Arduino RFID Library for MFRC522

My problem is the following: Tested individually, each reader works fine. Once plugged in all at once nothing works.

void setup() {
	Serial.begin(9600);		// Initialize serial communications with the PC
	while (!Serial);		// Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
	SPI.begin();			// Init SPI bus
	mfrc522.PCD_Init();		// Init MFRC522
	delay(4);				// Optional delay. Some board do need more time after init to be ready, see Readme
	mfrc522.PCD_DumpVersionToSerial();	// Show details of PCD - MFRC522 Card Reader details
	Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
Scan PICC to see UID, SAK, type, and data blocks...
Firmware Version: 0xF9 = (unknown)
Scan PICC to see UID, SAK, type, and data blocks...
Firmware Version: 0xC0 = (unknown)
Scan PICC to see UID, SAK, type, and data blocks...
Firmware Version: 0xF0 = (unknown)
Scan PICC to see UID, SAK, type, and data blocks...
Firmware Version: 0x38 = (unknown)
Scan PICC to see UID, SAK, type, and data blocks...
Firmware Version: 0x78 = (unknown)
Scan PICC to see UID, SAK, type, and data blocks...

As you can see from the output, everytime I reset the arduino I'm getting a different firmware version. From what I could gather on the internet, this is due to electromagnetic interference being present in the SPI bus and corrupting the data. I was concidering swapping for a shielded cable or just wraping foil around my cables. I have about 50 cm of extra cable that isn't needed on the SPI bus and CS line. I could cut it shorter. Would that help?

I've also read that lowering the SPI frequency could help.

Maybe there is a more appropriate communication for my particular case?
I tought that SPI would be better then I2C :confused:

Also, I'm using a TXS0108E from sparkfun as a level shifter betwen my nano and the RC522s. I don't know if maybe the data corruption could come from there...

Anyway, if anybody has any helpful comment or suggestion, I'll gladly take them.
I've been working on this for weeks now and I can't get it to work.

Please post schematics. It looks like You have one instance of the card reader but 4 of them connected. If so, that is completely wrong.

@xlap
Please also show your full code

I don't really need help with the code. I was looking for guidance on the hardware side of things, but sure here you go:

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_1_PIN        10         // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 2
#define SS_2_PIN        5          // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 1
#define SS_3_PIN        4        // Configurable, take a unused pin, only HIGH/LOW required, must be different to SS 2
#define SS_4_PIN        3

#define NR_OF_READERS   4

byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN, SS_4_PIN };

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.

/**
 * Initialize.
 */
void setup() {

  Serial.begin(9600); // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

  SPI.begin();        // Init SPI bus

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
    Serial.print(F("Reader "));
    Serial.print(reader);
    Serial.print(F(": "));
    mfrc522[reader].PCD_DumpVersionToSerial();
  }
}

/**
 * Main loop.
 */
void loop() {

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    // Look for new cards

    if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
      Serial.print(F("Reader "));
      Serial.print(reader);
      // Show some details of the PICC (that is: the tag/card)
      Serial.print(F(": Card UID:"));
      dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
      Serial.println();
      Serial.print(F("PICC type: "));
      MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
      Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));

      // Halt PICC
      mfrc522[reader].PICC_HaltA();
      // Stop encryption on PCD
      mfrc522[reader].PCD_StopCrypto1();
    } //if (mfrc522[reader].PICC_IsNewC
  } //for(uint8_t reader
}

/**
 * Helper routine to dump a byte array as hex values to Serial.
 */
void dump_byte_array(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}

I'm mostly interested as to why the firmware version keeps changing between reboot. I was suspecting data corruption on the SPI bus, but I guess it could be a faulty library too?

Did you test one reader using your multi-reader code with NR_READERS set to one (1)?

And try that one sensor with each SS pin you've chosen?

Just change the pin at [0] in the array o' pins.

Try that if not.

a7