Teensy 3.2 with multiple RFID-RC522 Readers

Status
Not open for further replies.

Doogle

New member
I am trying to run 2 RFID-RC522s on a Teensy 3.2. Works really well with one reader, as soon as I add in the second reader, I get an error message*
I have clk, MISO, MISI, GND, and 3.3V all connected, and the reset and cs pins individually connected to each RFID. I noticed on an oscilloscope that the MISO line drops to 1V when the second RFID is connected. Do I need to hold the reset line low for the tags that I am not reading, I tried that but couldn't figure out how to do that.

*Error Message
Reader 0: Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?
Reader 1: Firmware Version: 0x0 = (unknown)
WARNING: Communication failure, is the MFRC522 properly connected?



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

#define RST_1_PIN       0          
#define RST_2_PIN       1          
#define SS_1_PIN        4          
#define SS_2_PIN        5          

#define NR_OF_READERS   2

byte ssPins[] = {SS_1_PIN, SS_2_PIN};
byte rstPins[] = {RST_1_PIN, RST_2_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], rstPins[reader]); // 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);
  }
}
 
Can you try with just SPI device, and with 2 resistors on the MISO pin, as described here:

https://www.dorkbotpdx.org/blog/paul/better_spi_bus_design_in_3_steps

The idea is to check whether the RFID reader is properly disabling its MISO pin when not in use. If it is doing this, you should see about 1.65V on the MISO pin due to the resistors. But if it's continuing to drive MISO after CS is high, you'll see either 0 volts or 3.3V as the RFID reader continues driving a logic level onto the MISO line.

Sadly, there are many SPI chips which do not properly disable MISO. RS8875 and CC3000 are notorious ones. Maybe these RFID readers are too? If that's the case, please try to name & shame the specific RFID reader model. It's unlikely the manufacturer will ever fix it, but at least there's a good chance others trying to use it will find this thread if the info has part numbers or other search-likely terms.
 
Thanks for the reply PaulStoffregen. Tried it, looks like the RFID is still trying to drive the MISO line.
 
That's so sad. I guess we can add RC522 to the list of badly designed SPI chips that don't properly tri-state MISO.

To get 2 of these to work together, or even 1 to work together with any other SPI chips, you'll need to add a 74HC125 or similar tri-state buffer chip. See the description on that web page for details.
 
Unfortunately I made PCBs already without the buffer chip. These RFIDs have a reset line, that I individually tied each to a GPIO pin on the TEENSY. When I get a minute, I am going to try pulling that line low on the reader that I am not communicating with to see if that changes anything with the MISO line. According to the documentation it should.
 
Status
Not open for further replies.
Back
Top