Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RST not works #599

Open
alex-eri opened this issue Apr 13, 2023 · 1 comment
Open

RST not works #599

alex-eri opened this issue Apr 13, 2023 · 1 comment
Labels
bug 🐛 a not intended feature hardware 🔌 not a problem with the software

Comments

@alex-eri
Copy link

alex-eri commented Apr 13, 2023

Step 1: Describe your environment

  • OS version: Ubuntu 22.04
  • Arduino IDE version: PlatformIO 3.1.1
  • MFRC522 Library version: 1.4.10
  • Arduino device: ESP32-WROOM-32D
  • MFRC522 device: XFW-ETLIVE MINI RFID-RC522

Step 2: Describe the problem

Affected file(s) or example(s):

Steps to reproduce:

I connect to module ESP32-WROOM-32D without devkit:

  • io16-rst
  • io17-irq
  • io5-ss

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.

    pinMode(RFID_RST_PIN, OUTPUT);
    digitalWrite(RFID_RST_PIN, LOW);
    delay(2);
    digitalWrite(RFID_RST_PIN, HIGH);
    delay(2);

    mfrc522.PCD_Init(RFID_SS_PIN, 255); 
    //mfrc522.PCD_Init();

Maybe INPUT_PULLDOWN here is better?

pinMode(_resetPowerDownPin, INPUT);

	pinMode(_resetPowerDownPin, INPUT_PULLDOWN);
@nobur
Copy link

nobur commented May 6, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 a not intended feature hardware 🔌 not a problem with the software
Projects
None yet
Development

No branches or pull requests

3 participants