miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.74k stars 1.43k forks source link

SD card reader and RFID reader #578

Closed podaen closed 2 years ago

podaen commented 2 years ago

How to use SD card reader and a rfid card together?

What do I need to do on the config of the spi in this library? I watched topic 191 for multiple rfid readers but I can't make it work.

I config the sd card reader for multieple devices on the spi. Ones I use the sd card reader the rfid stops on this line

SPI.beginTransaction(SPISettings(MFRC522_SPICLOCK, MSBFIRST, SPI_MODE0)); // Set the settings to work with SPI bus

podaen commented 2 years ago

I found this comment you told one before.

In SPI, the communication "happens" only when the CS (chip select) signal is pulled low (by the master), acting as an "addressing" signal. In this way, you can have many chips sharing the MISO/MOSI/CLK signals. In idle state (no communication at all), all the CS signals should be pulled high. When the master wants to speak with a slave, it (the master) selects the slave by pulling the corresponding CS signal low, sends/receives the data and pulls the CS high. Exactly this is happening in the MFRC522 library - when the communication ends, the CS returns to high. And exactly in the same way should happen in the case of SD communication also - the SD's CS (SS) signal should return to high after communication finishes.

What I understand is that two devices can not be used on the same time. I need to close down the transaction before I can start an other one, by turning the cs pin to high after the communication ends.

podaen commented 2 years ago

I have some improvements. Now I doesn't stop running on the begintransaction after the changes I have made for multiple devices on the spi. But it doesn't find my new card presented.

This is the code I use

    if (!mfrc522.PICC_IsNewCardPresent())
    {
        mfrc522.PCD_Reset();
        return;
    }
    Serial.println("select card");
    if (!mfrc522.PICC_ReadCardSerial())
    {
        mfrc522.PCD_Reset();
        return;
    }
    readingData();
    mfrc522.PICC_HaltA();
    mfrc522.PCD_StopCrypto1();
podaen commented 2 years ago

ok. I just found out... The transaction looks like this.

SPI.beginTransaction(SPISettings(x, x, x)); digitalWrite(chipSelectPin, LOW); SPI.transfer(mybyte1); SPI.transfer(mybyte2); digitalWrite(chipSelectPin, HIGH); SPI.endTransaction();

Soo the communication is end. I will close it now.