You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
#include<SPI.h>
#include<MFRC522.h>
#defineRST_PIN3// Configurable, see typical pin layout above
#defineSS_PIN5// Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instancevoidsetup()
{
Serial.begin(115200); // Initialize serial communications with the PCwhile (!Serial)
; // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
Serial.println("Testing out connecting to SPI ");
SPI.begin(7, 11, 9, 5); // Init SPI bus// SPI.begin(); // Init SPI bus
Serial.println("Testing out connecting to mfrc");
mfrc522.PCD_Init(); // Init MFRC522delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
voidloop()
{
if (!mfrc522.PICC_IsNewCardPresent())
{
return;
}
if (!mfrc522.PICC_ReadCardSerial())
{
return;
}
MFRC522::Uid *uid = &mfrc522.uid;
for (byte i = 0; i < uid->size; i++)
{
// After F hex wraps around to 10 so print space and 0 to go to newif (uid->uidByte[i] < 0x10)
Serial.print(F(" 0"));
else
Serial.print(F(""));
Serial.print(uid->uidByte[i], HEX);
}
Serial.print("\n");
}
However when using this library, I seem to be getting the log: Read/write test failed followed by repeating messages of:
E (2220) rc522: write: Unknown transport
E (2220) rc522: Failed to write data (err: ESP_ERR_INVALID_STATE)
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:
constuint8_ttest_addr=RC522_MOD_WIDTH_REG, test_val=0x25;
uint8_tpass=0;
for (uint8_ti=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)
{
ESP_LOGE(TAG, "Read test failed (err: %s)", esp_err_to_name(err));
}
if (err==ESP_OK&&tmp==i)
{
pass=1;
}
else
{
ESP_LOGE(TAG, "Invalid return %d, expected %d", tmp, i);
}
}
else
{
ESP_LOGE(TAG, "Write test failed (err: %s)", esp_err_to_name(err));
}
if (pass!=1)
{
ESP_LOGE(TAG, "Read/write test failed");
// For some reason the task still goes on in the background, giving ESP_ERR_INVALID_STATE when trying to writerc522_destroy(rc522);
returnerr;
}
}
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 with rc522_read sorry 🥲.
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 😆.
The text was updated successfully, but these errors were encountered:
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 with
rc522_read
sorry 🥲.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 😆.
The text was updated successfully, but these errors were encountered: