Am trying to troubleshoot some lockups on an RC522 on an ESP8266, and have already done some remedial work (Convert String to char[] arrays).
I still get some lockups and wanted to confirm something. The instructions say that the PICC_HaltA should be run after reading the card, does the “mfrc522.PICC_GetType” command count as a ‘reading’? Also, I have a delay before the PICC_HaltA, to prevent re-reading of the swipe and give the user time to remove the fob. Should I place this affer the PICC_HaltA or remove it entirely and let the swipe sensor modules detect a change?
(I don’t want to post the entire project, it’s 1100+ lines, I am after clarification on best practice at the moment).
Thanks, Ian
void RfidScan(){
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
// Serial.println("Card detected");
return;
}
Serial.print(F("\nPICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
// Check is the PICC of Classic MIFARE type
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F("Your q / is not of type MIFARE Classic."));
return;
}
.....
// Wait so card can be removed- 1 second
delay (1000);
// Halt PICC
mfrc522.PICC_HaltA();
// Stop encryption on PCD
mfrc522.PCD_StopCrypto1();
}