Board : Arduino UNO R3 / ATmega328P
Library : MFRC522
MFRC522 dont' read cards after 170 readings.
it also don't work at other example codes.
It works when I upload the bootloader.
What's the problem with this?
// RFID-Read NUID
#include <SPI.h>
#include "MFRC522.h"
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
// Init array that will store new NUID
byte nuidPICC[4];
void setup() {
Serial.begin(115200);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
//Serial.println(F("This code scan the MIFARE Classsic NUID."));
//Serial.print(F("Using the following key:"));
//printHex(key.keyByte, MFRC522::MF_KEY_SIZE);
if (rfid.PCD_PerformSelfTest()) Serial.println("Passed Self-Test");
}
void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! rfid.PICC_IsNewCardPresent())
return;
// Verify if the NUID has been readed
if ( ! rfid.PICC_ReadCardSerial())
return;
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print( rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print( rfid.uid.uidByte[i] , HEX);
}
//Serial.print(F("PICC type: "));
//MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
//Serial.println(rfid.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(" wrong!"));
// return;
// }
if (rfid.uid.uidByte[0] != nuidPICC[0] ||
rfid.uid.uidByte[1] != nuidPICC[1] ||
rfid.uid.uidByte[2] != nuidPICC[2] ||
rfid.uid.uidByte[3] != nuidPICC[3] ) {
Serial.println(F(" new card"));
// Store NUID into nuidPICC array
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
}
else Serial.println(F(" previous card"));
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}