Closed ProPablo closed 2 weeks ago
I am experiencing the same error. I checked the rc522_start procedure and I don't fully understand it :
uint8_t pass = 0;
for(uint8_t i = test_val; i < test_val + 2; i++) {
err = rc522_write(rc522, test_addr, i);
if(err == ESP_OK) {
err = rc522_read(rc522, test_addr, &tmp);
if(err == ESP_OK && tmp == i) {
pass = 1;
}
}
if(pass != 1) {
ESP_LOGE(TAG, "Read/write test failed");
rc522_destroy(rc522);
return err;
}
}
pass
boolean is only used inside the loop, so I would suggest to also declare it inside the loop.ESP_OK
, so it is not possible to detect the errorpass
variable is not reset to zero. I really think that this is a mistake and the pass
variable should be declared and set to zero inside the loop. But anyhow, this does not solve our problem. The value 0x25
(or 37 decimal) is written at the address RC522_MOD_WIDTH_REG
= 0x24
= 36 and this register is writable, so in theory it should work. Note however that this error is not always reproducible. I've experienced that sometimes it fails and sometimes it works.
I am using an esp32s2 mini, and I bought my card readers from both amazon and aliexpress and it seems both work with the arduino library for rfid.
I used the following arduino code:
However when using this library, I seem to be getting the log:
Read/write test failed
followed by repeating messages of:Code:
Having a deeper look at the source code, it turns out the invalid state error is there because in
rc522_start
if the test fails,rc522_destroy
is called causing the SPI device to be destroyed but the task still remains for some reason.I had a further look and changed the source of the read write test to:
I get the output:
Invalid return 0, expected 37
. So im guessing either the read or the write couldve failed here. I might try testing a known readable value, on the datasheet it says the address 37h is the VersionReg but im not sure how to use the SPI interface especially withrc522_read
sorry :smiling_face_with_tear:.I can't use pin 19 for sck as recommended by the library and the video as it isnt exposed through the dev board im using.
For now im throwing more hardware at the problem and using the pn532 :laughing:.