cembeddedesp32rfid

RC-522 not interrupting and not detecting rfid tag


I'm trying to read data from a RC-522 with an ESP32 in C.The problem is that even if I aproach the card to the RFID reader it doesn't modify the value in ComIrqReg.

     bool mfrc522_request(void) { 
            mfrc522_write(BitFramingReg, 0x07);  // Clear collision bits
            mfrc522_write(FIFOLevelReg, 0x80);   // Flush FIFO 
            mfrc522_write(FIFODataReg, PICC_REQIDL); 
            mfrc522_write(CommandReg, PCD_TRANSCEIVE); 
            mfrc522_write(BitFramingReg, 0x80);  // Start transmission           
                 // Wait for response (max 50ms)
                for (int i = 0; i < 50; i++) {
                    uint8_t irq = mfrc522_read(ComIrqReg);
                    if (irq & 0x20) {  // RxIRq triggered
                        uint8_t err = mfrc522_read(ErrorReg);
                        if (!(err & 0x1B)) {
                            uint8_t len = mfrc522_read(FIFOLevelReg);
                            return (len > 0);
                        }
                    }
                    vTaskDelay(1);
                }
                return false;
            }

Interuptions are never triggered. I assume it means that the module doesn't read the card. The configurations are:

                mfrc522_write(TModeReg, 0x8D);
                mfrc522_write(TPrescalerReg, 0x3E);
                mfrc522_write(TReloadRegL, 30);
                mfrc522_write(TReloadRegH, 0);
                mfrc522_write(TxControlReg, 0x83);
                mfrc522_write(ModeReg, 0x3D);
                mfrc522_write(CommandReg, PCD_IDLE);
                mfrc522_write(ComIEnReg, 0x20);
                mfrc522_write(DivIEnReg, 0x00);
           

It is not a hardware problem. The module works fine in Arduino.The cabling is fine aswell. Also If someone may have learning resources I appreciate it! Thanks

I tried to read the RFID card, but the module doesn't change register values in FIFOLevelReg, FIFODataReg, and ComIrqReg. The error register is also empty.


Solution

  • The registers weren't configured properly. The actual settings are as following:
    mfrc522_write(CommandReg, PCD_IDLE); //

    mfrc522_write(ComIrqReg, 0x7F); //Clears the interuption Register

    mfrc522_write(FIFOLevelReg, 0x80); // Flush FIFO

    mfrc522_write(ErrorReg, 0x00); //Clears the Error Register

    mfrc522_write(FIFODataReg, PICC_REQALL); // Configure FIFO Buffer to read requests.

    mfrc522_write(BitFramingReg, 0x07); // 7 valid bits, no CRC

    mfrc522_write(CommandReg, PCD_TRANSCEIVE);

    mfrc522_write(BitFramingReg, 0x87); // Start transmision.

    After that configuration there will be an interupt that marks a request. In the FIFODataReg there will be the answer to the request (Answer to Request Type A , type A is the type of the card). Now we need to read the actual data on the tag.

        mfrc522_write(CommandReg, PCD_IDLE);
        mfrc522_write(ComIrqReg, 0x7F);
        mfrc522_write(FIFOLevelReg, 0x80);   // Flush FIFO
        mfrc522_write(ErrorReg, 0x00);
    
        // Send ANTICOLLISION command
        mfrc522_write(FIFODataReg, PICC_SEL_CL1);  // 0x93
        mfrc522_write(FIFODataReg, 0x20);          // Request all bytes from UID
    
        mfrc522_write(BitFramingReg, 0x00);        // All bits valid, no framing
        mfrc522_write(CommandReg, PCD_TRANSCEIVE);
        mfrc522_write(BitFramingReg, 0x80);        // Start transmission
    

    And after that we read the FIFOLevelReg to see how many valid bytes are in the FIFO Buffer, and after that we read from FIFODataReg.