Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading failed: A buffer is not big enough #11

Open
ear9mrn opened this issue Nov 24, 2021 · 0 comments
Open

Reading failed: A buffer is not big enough #11

ear9mrn opened this issue Nov 24, 2021 · 0 comments

Comments

@ear9mrn
Copy link

ear9mrn commented Nov 24, 2021

In my loop() I have the following:

void loop()
{


  if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ){
    delay(30);
    return;
  }

  
  Serial.print(F("Card UID:"));
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if(mfrc522.uid.uidByte[i] < 0x10)
      Serial.print(F(" 0"));
    else
      Serial.print(F(" "));
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();

  readstatus = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522.uid));
  if (readstatus != MFRC522::STATUS_OK) {
    Serial.print(F("Authentication failed: "));
    Serial.println(mfrc522.GetStatusCodeName(readstatus));
    
    //reset everything for the next card
    mfrc522.PCD_StopCrypto1();
    return;
  }
    
  byte buffer[18];
  readstatus = mfrc522.MIFARE_Read(block, buffer, &len);
      
  if (readstatus != MFRC522::STATUS_OK) {
    Serial.print(F("Reading failed: "));
    Serial.println(mfrc522.GetStatusCodeName(readstatus));
    
    //reset everything for the next card
    mfrc522.PCD_StopCrypto1();
    return;
  }

  //reset everything for the next card
  mfrc522.PCD_StopCrypto1();
  
  String value = "";
  for (uint8_t i = 0; i < 16; i++)
  {
      value += (char)buffer[i];
  }
  value.trim();
  Serial.println(value);
  
}

I am reading the content of block 4 of the card.

In general things work well but eventually (after about 20-30 reads) I get the following error.

Reading failed: The CRC_A does not match.

Which in itself is not a problem. Only issue is that on all following reads I get the this error:

Reading failed: A buffer is not big enough.

I then have to restart my Arduino (D1 mini). Is this a bug or a problem with how I have set the code up?

Thanks,

Pete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant