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

Can not wake up PICC #38

Closed
omersiar opened this issue Aug 30, 2014 · 5 comments
Closed

Can not wake up PICC #38

omersiar opened this issue Aug 30, 2014 · 5 comments

Comments

@omersiar
Copy link
Contributor

This simple code tries to Wake UP a Halted PICC, but it can not. What is wrong?

include <SPI.h> // RC522 Module uses SPI protocol

include <MFRC522.h> // Library for Mifare RC522 D

define SS_PIN 10

define RST_PIN 9

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

void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Initialize serial communications with PC
SPI.begin(); // MFRC522 Hardware uses SPI protocol
mfrc522.PCD_Init(); // Initialize MFRC522 Hardware

}

void loop() {
byte bufferATQA[10];
byte bufferSize[10];
// put your main code here, to run repeatedly:
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
Serial.println("There is no PICC");
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Cannot get UID");
return;
}
Serial.println("GOT UID");
mfrc522.PICC_HaltA();
Serial.println("PICC Halted");
delay(100);
Serial.println("Im trying to Wake Up Halted PICC");
mfrc522.PICC_WakeupA(bufferATQA, bufferSize); //wake up PICC which was previously Halted
delay(100);
mfrc522.PICC_RequestA(bufferATQA, bufferSize);
delay(100);
Serial.println("PICC Should Wake Up");
delay(100);
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("Tried get UID but no luck");
}
delay(1000);
}

@mdxs
Copy link
Contributor

mdxs commented Nov 11, 2014

Look at the implementation of MFRC522::PICC_IsNewCardPresent() in the .cpp, from that I guess you will need to use:

  byte bufferATQA[10];
  byte bufferSize = sizeof(bufferATQA);
  byte result;
  ...
  result = mfrc522.PICC_WakeupA(bufferATQA, &bufferSize);
  if (result != STATUS_OK) {
    // report some issue
    return;
  }
  ...
  result = mfrc522.PICC_RequestA(bufferATQA, &bufferSize);
  if (result != STATUS_OK) {
    // report some issue
    return;
  }
  ...

@mdxs
Copy link
Contributor

mdxs commented Mar 16, 2015

@omersiar : could this issue be closed now?

@omersiar
Copy link
Contributor Author

Yes it can be closed.

@Lotrax
Copy link

Lotrax commented Mar 12, 2019

I have the same problem as @omersiar and have looked at the .cpp but it seems I'm missing something. Currently doing it as follows:

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         13          // Configurable, see typical pin layout above
#define SS_1_PIN        2         // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 2
#define SS_2_PIN        3          // Configurable, take a unused pin, only HIGH/LOW required, must be diffrent to SS 1
#define SS_3_PIN        4
#define SS_4_PIN        5
#define SS_5_PIN        6
#define SS_6_PIN        7

#define NR_OF_READERS   6

byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN, SS_4_PIN, SS_5_PIN, SS_6_PIN};

byte bufferATQA[2];
byte bufferSize = sizeof(bufferATQA);

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.

void setup() {
  Serial.begin(9600); // Initialize serial communications with the PC
  SPI.begin();        // Init SPI bus
  delay(500);

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN); // Init each MFRC522 card
    delay(100);
    Serial.print(F("Reader "));
    Serial.print(reader);
    Serial.print(F(": "));
    mfrc522[reader].PCD_DumpVersionToSerial();
  }
}

/**
   Main loop.
*/
void loop() {

  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    mfrc522[reader].PICC_WakeupA(bufferATQA, bufferSize);

    if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
      Serial.print(F("Reader "));
      Serial.print(reader);
      dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
      Serial.println();

      mfrc522[reader].PICC_HaltA(); //Remove so cards stay readable
      mfrc522[reader].PCD_StopCrypto1();
    }
  }
}

void dump_byte_array(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }

I know I can just leave out mfrc522[reader].PICC_HaltA(); but I want more control over it, I want to keep reading all readers except those I have halted. I want to start those readers that are relevant.

@Lotrax
Copy link

Lotrax commented Mar 13, 2019

Another user, @akellai, has created a fast_reset function, which does exactly what I wanted PICC_WakeupA to do (or expected it to do). It's perhaps a work around, but it works. Since Google led me to this question, I suspect others will find it to, so here is a link to akellai's comment and my own which is an adapted code of akellia's for multiple readers.

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

3 participants