OSSLibraries / Arduino_MFRC522v2

https://osslibraries.github.io/Arduino_MFRC522v2/
GNU Lesser General Public License v2.1
101 stars 39 forks source link

Communication failure with MFRC522v2, but the original MFRC522 had no such issues #27

Open arseni-mourzenko opened 1 year ago

arseni-mourzenko commented 1 year ago

I'm trying to read Mifare Classic 1K cards using Seeeduino Lotus. It works with the original https://github.com/miguelbalboa/rfid library, detecting the card and showing its UID.

However, when I try MFRC522v2 version 2.0.4 and use the sample code from the documentation, it shows:

= (unknown) WARNING: Communication failure, is the MFRC522 properly connected? Scan PICC to see UID, SAK, type, and data blocks...

Note that the wiring is exactly the same in both cases, with the default pins being used, as specified in the documentation. If I upload back the original sketch, it works.

I noticed that the example from the original MFRC522 library specifies both the SPI SS pin and the reset pin like this:

#define RST_PIN 9
#define SS_PIN 10

however the example from has only the SS pin specified:

MFRC522DriverPinSimple ss_pin(10);

Is this the issue? How do I tell what's the reset pin?

nobur commented 1 year ago

Hi,

it seems that using hardware reset line appears useless to devs as you can read in the source comments:

// So far just using software based reset had no disadvantage so skip any reset pin related code.

From my own experience, there should be a hardware reset line management for 2 main reasons :

I strongly suggest you to implement this on your own as it's just a matter of pulling reset pin down then up with a short delay in between.

byte _resetPowerDownPin = GPIO_NUM_XXX

void setup()
{
...
pinMode(_resetPowerDownPin, OUTPUT);
...
}

void PCD_Powerdown()
{
    digitalWrite(_resetPowerDownPin, LOW);
}

void PCD_PowerUp()
{
    digitalWrite(_resetPowerDownPin, HIGH);
}

void PCD_HardReset()
{
    digitalWrite(_resetPowerDownPin, LOW);
    delayMicroseconds(2);   //In order to perform a reset, the signal must be LOW for at least 100 ns => 2us is more than enough
    digitalWrite(_resetPowerDownPin, HIGH);
    delay(50);
}

I personnally trigger a hardreset every time the microcontroller starts to ensure the chip is always properly working.

Few things to keep in mind after sending a hard reset :

Regards

P.S. I hope I'm clear (sorry for my English ;) )