Problem with RC522

I have a system where I need to detect the constant state of a tag present on the RC522. If the same tag stays present I need to keep to keep reading that the tag is present. If the tag is taken away then I need to know that no tag is present. If a tag switches from one to another I need to know the new one is present.

I am currently using this code:

if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
FormatBytes(szCards, mfrc522.uid.uidByte, mfrc522.uid.size);
strcpy(szCards, "-----------");

The problem is that even though the tag is physically resting on the reader I am getting drops. I tried putting in a "debounce" where the card has to be missing for a certain amount of time, but regardless of what time I put for that I get instances that exceed it (up to 2000ms).

It looks like from the code that the reader sort of "goes to sleep" if the same card is present for an extended period of time. So is there a different way I can test that a card is present other than PICC_IsNewCardPresent?


After poking around through the library, and trying out a few things, I have come up with a solution. Instead of calling PICC_IsNewCardPresent() I use this code:

mfrc522.MIFARE_UnbrickUidSector(false); // Not sure if this is needed, but it works so I will leave it
byte bufferATQA[2];
byte bufferSize = sizeof(bufferATQA);

mfrc522.PICC_WakeupA(bufferATQA, &bufferSize);

Then, I read. I either get a tag (the same or a new one), or the read fails indicating no card. This solved my problem.