Hello, I am trying to get 16 RC522 modules to work with an ATMega1284. The issue is I can not get the ATMega1284 to stop crashing. I am using an LD33V to power all 16 (Which should be plenty since the LD33V can output 800mA and each RC522 unit takes a maximum of 26mA). As seen in the photo below, each reader successfully initiates, but when the ATMega1284 starts to go read the readers for any available tags, it crashes randomly and it crashes on a different reader every time.
Here is my code, this is where I got to to make it work the best AND read cards before it crashes:
#include <SPI.h>
#include <MFRC522.h>
#include <MemoryFree.h>
// PIN Numbers : RESET + SDAs
//Pins 0-3, 16-17, 24-31
#define RST_PIN 4
#define R1 0
#define R2 1
#define R3 2
#define R4 3
#define R5 13
#define R6 14
#define R7 16
#define R8 17
#define R9 24
#define R10 25
#define R11 26
#define R12 27
#define R13 28
#define R14 29
#define R15 30
#define R16 31
#define NR_OF_READERS 16
byte ssPins[] = {R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, R13, R14, R15, R16};
// Create an MFRC522 instance :
MFRC522 mfrc522[NR_OF_READERS];
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
pinMode(RST_PIN, OUTPUT);
digitalWrite(RST_PIN, LOW); // mfrc522 readers hard power down.
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
pinMode(ssPins[reader], OUTPUT);
digitalWrite(ssPins[reader], HIGH);
}
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
//Serial.println(freeMemory());
delay(1);
mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN);
Serial.print(F("Pin "));
Serial.print(ssPins[reader]);
Serial.print(F("-Reader "));
Serial.print(reader);
Serial.print(F(": "));
mfrc522[reader].PCD_DumpVersionToSerial();
}
delay(5000);
}
void loop() {
for (uint8_t readerS = 0; readerS < NR_OF_READERS; readerS++) {
digitalWrite(ssPins[readerS], HIGH);
}
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
delay(10);
digitalWrite(ssPins[reader], LOW);
Serial.print(F("Reader "));
Serial.println(reader);
Serial.println();
// Looking for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()){
Serial.println(F("Read!!! "));
Serial.print(F(": Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println();
}
mfrc522[reader].PICC_HaltA();
mfrc522[reader].PCD_StopCrypto1();
}
}
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);
}
}
For the circuit, it is on a printed circuit board so connections shouldn’t be an issue(Which seems to be proven with the successful initiation of all 16 readers.)
I’ve tried adding more available power from other external sources with no luck, I’ve tested the voltage and signals of the lines all over the board and they all seem fine also. the ATMega1284 is not running out of RAM either as I tested that theory also.
Has anyone ran into a problem like this before or have any suggestions on what I could try? (I have a feeling it is with the reset pin and the SS pins to all of the readers. But I haven’t had any luck with any of my attempts.)