miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.74k stars 1.43k forks source link

ESP8266: PCD_Authenticate() failed: Timeout in communication. #548

Closed steand closed 3 years ago

steand commented 3 years ago

Step 1: Describe your environment

Step 2: Describe the problem

On the arduino UNO the code works ready. If I switch to WeMos D1 mini/NodeMCU I get: PCD_Authenticate() failed: Timeout in communication. I test with different card (all can read with my mobil).

Observed Results:

Firmware Version: 0x92 = v2.0
Scan PICC to see UID, SAK, type, and data blocks...
Card UID: 39 CD 80 C8
Card SAK: 08
PICC type: MIFARE 1KB
Sector Block   0  1  2  3   4  5  6  7   8  9 10 11  12 13 14 15  AccessBits
  15     63  PCD_Authenticate() failed: Timeout in communication.
  14     59  PCD_Authenticate() failed: Timeout in communication.
  13     55  PCD_Authenticate() failed: Timeout in communication.
  12     51  PCD_Authenticate() failed: Timeout in communication.
  11     47  PCD_Authenticate() failed: Timeout in communication.
  10     43  PCD_Authenticate() failed: Timeout in communication.
   9     39  PCD_Authenticate() failed: Timeout in communication.
   8     35  PCD_Authenticate() failed: Timeout in communication.
   7     31  PCD_Authenticate() failed: Timeout in communication.
   6     27  PCD_Authenticate() failed: Timeout in communication.
   5     23  PCD_Authenticate() failed: Timeout in communication.
   4     19  PCD_Authenticate() failed: Timeout in communication.
   3     15  PCD_Authenticate() failed: Timeout in communication.
   2     11  PCD_Authenticate() failed: Timeout in communication.
   1      7  PCD_Authenticate() failed: Timeout in communication.
   0      3  PCD_Authenticate() failed: Timeout in communication.

Relevant Code:

#include <Arduino.h>
#include <SPI.h>
#include <MFRC522.h>
#include "Logging.h"

const int RST_PIN = D1; // Reset pin
const int SS_PIN = D8;  // Slave select pin

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

void setup() {
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)

Serial.println();
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(100);
mfrc522.PCD_AntennaOn();
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details

Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

}

void loop() {

if (!mfrc522.PICC_IsNewCardPresent()) return;
if (!mfrc522.PICC_ReadCardSerial()) return;

// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_ReadCardSerial();
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
// mfrc522.PICC_DumpDetailsToSerial(&(mfrc522.uid));
// mfrc522.PICC_DumpMifareUltralightToSerial();
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();

}
steand commented 3 years ago

bug found. I call mfrc522.PICC_ReadCardSerial(); twice.