Getting version B2 on RFID-RC522 via SPI communication

Hi there, I tried to do the selftest on MFRC522 through SPI. I have followed the instruction but instead of getting the expected version and value of FIFO buffer stated in the datasheet. I got a different output.

Output:
Version B2
Self-test result:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 E9 C B9 F7 CF DF
F C6 5E A6 35 90 F2 11 64 E2 E 36 2D CA DD A3
D1 1 1B 61 64 3A FB A8 1A 28 37 EE 53 61 37 A3

Below are the selftest instruction along with my code for it.

#include <SPI.h>

const int chipSelectPin = 10;

void setup() {
    Serial.begin(9600);
    SPI.begin();
    
    pinMode(chipSelectPin, OUTPUT);
    digitalWrite(chipSelectPin, HIGH);
    
    performSelfTest();
}

void loop() {
    // Your main code here
}

void performSelfTest() {
    softReset();
    clearInternalBuffer();
    enableSelfTest();
    writeFIFO(0x00);
    startSelfTest();
    readSelfTestResult();
}

void softReset() {
    writeRegister(0x01, 0x0F);  // CommandReg: SoftReset command
}

void clearInternalBuffer() {
    for (int i = 0; i < 25; i++) {
        writeRegister(0x09, 0x00);  // FIFODataReg: write 0x00 to FIFO buffer
    }
}

void enableSelfTest() {
    writeRegister(0x36, 0x09);  // AutoTestReg: enable self-test
}

void writeFIFO(byte value) {
    writeRegister(0x09, value);  // FIFODataReg: write value to FIFO buffer
}

void startSelfTest() {
    writeRegister(0x01, 0x03);  // CommandReg: start CalcCRC command
}

void readSelfTestResult() {
    byte version = readRegister(0x37);
    Serial.println(version,HEX);
    Serial.println("Self-test result:");
    for (int i = 0; i < 64; i++) {
        byte result = readRegister(0x09);  // FIFODataReg: read result from FIFO buffer
        Serial.print(result, HEX);
        Serial.print(" ");
        if ((i + 1) % 16 == 0) {
            Serial.println();
        }
    }
}

void writeRegister(byte reg, byte value) {
    digitalWrite(chipSelectPin, LOW);
    SPI.transfer((reg << 1) & 0x7E);  // Address format: 0XXXXXX0 for write operation
    SPI.transfer(value);
    digitalWrite(chipSelectPin, HIGH);
}

byte readRegister(byte reg) {
    digitalWrite(chipSelectPin, LOW);
    SPI.transfer(((reg << 1) & 0x7E) | 0x80);  // Address format: 1XXXXXX1 for read operation
    byte value = SPI.transfer(0x00);
    digitalWrite(chipSelectPin, HIGH);
    return value;
}

Many of the cheap RC522 boards yo can buy are wired such that you can't use them in SPI mode. Are you sure you ahve one that will work with SPI?

Yes, I am quite sure of it, I am using this kind of RFID-RC522 board. I did tested it using the DumpInfo example and it works.

Here is my wire setup:
SS- pin 10
MOSI- pin 11
MISO- pin 12
SCLK- pin 13
GND -GND
RST- pin 5
VCC- 3.3V

Fine.
What sort of Arduino are you using? Is it a 3V3 type of processor then fine, otherwise those outputs will need level shifting of some sort.

Hi. I also have an MFRC522 board which gives version B2, instead of the expected 91/92. Checking the RFID library driver code, it also checks for version 88 which is "Fudan Semiconductor FM17522 clone". I am thinking the B2 version is also a clone of some kind.

In your code I notice you are not waiting for the self test to finish before reading from the FIFO. I expect the behavior is: the first 0s you read are because the FIFO is empty and the self test is still in progress, then you start reading the test result.

You can wait for the result to finish by: looping until FIFOLevelReg is 64, or until CommandReg reports the Idle Command (the library driver uses the first approach but both seem to work).

My result for the self test is below. Given the exact match to your string, I simply think we have some unofficial version of the chip with a different ID.

    00h, E9h, 0Ch, B9h, F7h, CFh, DFh, 0Fh
    C6h, 5Eh, A6h, 35h, 90h, F2h, 11h, 64h
    E2h, 0Eh, 36h, 2Dh, CAh, DDh, A3h, D1h
    01h, 1Bh, 61h, 64h, 3Ah, FBh, A8h, 1Ah
    28h, 37h, EEh, 53h, 61h, 37h, A3h, C7h
    E9h, 83h, 63h, ECh, BEh, D6h, 24h, 71h
    1Eh, A9h, 6Dh, DAh, D4h, FDh, FEh, EBh
    6Dh, 85h, 9Ch, E6h, 99h, F7h, 1Dh, D9h

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.