Open alex-eri opened 1 year ago
Hi,
I facing a similar issue and I made a similar workaround. After power on MFRC work perfectly but as soon as an esp restart is triggered ( by calling esp_restart or after an exception) it become unresponsive.
Reading the lib code, I can't understand how does this can work .
if (_resetPowerDownPin != UNUSED_PIN) {
// First set the resetPowerDownPin as digital input, to check the MFRC522 power down mode.
pinMode(_resetPowerDownPin, INPUT);
if (digitalRead(_resetPowerDownPin) == LOW) { // The MFRC522 chip is in power down mode.
pinMode(_resetPowerDownPin, OUTPUT); // Now set the resetPowerDownPin as digital output.
digitalWrite(_resetPowerDownPin, LOW); // Make sure we have a clean LOW state.
delayMicroseconds(2); // 8.8.1 Reset timing requirements says about 100ns. Let us be generous: 2μsl
digitalWrite(_resetPowerDownPin, HIGH); // Exit power down mode. This triggers a hard reset.
// Section 8.8.2 in the datasheet says the oscillator start-up time is the start up time of the crystal + 37,74μs. Let us be generous: 50ms.
delay(50);
hardReset = true;
}
}
if (!hardReset) { // Perform a soft reset if we haven't triggered a hard reset above.
PCD_Reset();
}
How can this line work if (digitalRead(_resetPowerDownPin) == LOW) {
?
In the MRFC533 documentation, it is stated that NRSTPD pin is Input only so there is no possibility to read anything relevant.
I guess that (depending on the microcontroller used) the level can be wrongly read as HIGH.
Will it be possible to change code to something like : in MRFC522.h
void PCD_Reset();
void PCD_HardReset();
in MRFC522.cpp
void MFRC522::PCD_HardReset()
{
if (_resetPowerDownPin != UNUSED_PIN)
{
digitalWrite(_resetPowerDownPin, LOW); // Make sure we have a clean LOW state.
delayMicroseconds(2); // 8.8.1 Reset timing requirements says about 100ns. Let us be generous: 2μsl
digitalWrite(_resetPowerDownPin, HIGH); // Exit power down mode. This triggers a hard reset.
// Section 8.8.2 in the datasheet says the oscillator start-up time is the start up time of the crystal + 37,74μs. Let us be generous: 50ms.
delay(50);
}
}
and finally update the PCD_init function by removing the level check on reset pin and calling the new function.
if (_resetPowerDownPin != UNUSED_PIN)
{
pinMode(_resetPowerDownPin, OUTPUT);
PCD_HardReset();
}
else
{ // Perform a soft reset if we haven't triggered a hard reset above.
PCD_Reset();
}
I didn't test this code myself now but I will soon ( and i guess others can also greatly improve this code ).
Regards.
Edit: Seems work correctly so far.
Step 1: Describe your environment
Step 2: Describe the problem
Affected file(s) or example(s):
Steps to reproduce:
I connect to module ESP32-WROOM-32D without devkit:
Same power source AMS1117.
Init with
mfrc522.PCD_Init(RFID_SS_PIN, RFID_RST_PIN);
Observed Results:
Radio chains Not starts. Cards not readed. But
PCD_PerformSelfTest
is OK. LOW on RFID_RST_PIN.Expected Results:
Working reader
Relevant Code:
I make this workaround: Reader works perfect.
Maybe
INPUT_PULLDOWN
here is better?https://github.com/miguelbalboa/rfid/blob/1e73cd34d977c5fe17fa5f2e2e8174650a572028/src/MFRC522.cpp#L208