Resetting a MF522 Serial 13.56MHZ RFID Reader/Writer to its defaults

I bought myself a Serial 13.56MHZ RFID Reader/Writer Module Kit on ebay that came with a RFID tag and card.

MF522 RFID reader

I was playing with it and the following code worked like a charm:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3);

unsigned char command, devnull;
unsigned int returnLength;

void setup()  
{
  Serial.begin(9600);

  Serial.println("Waiting for Card\n");
  mySerial.begin(9600);

   mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
}

void loop()
{
  if (mySerial.available()) {
    Serial.print("\n\rCARD SERIAL: ");
    for (unsigned int i=0; i<4 ;i=i){
      if (mySerial.available()) {
        Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
        i++;
      }
    }
    mySerial.write(0x02); //Send the command to RFID, please refer to RFID manual
  }
}       

void Get_Reply() {
  while (!mySerial.available());
  devnull = mySerial.read();
  while (!mySerial.available());
  returnLength = mySerial.read() - 1;

  for (unsigned int i=0;i< returnLength;i=i){
    //Serial.print("2"); 
    if (mySerial.available()) {
      //Serial.print("\n\ri is: ");Serial.print(i);Serial.print(" ");
      Serial.print(mySerial.read(),HEX); //Display the Serial Number in HEX
      Serial.print(" ");
      i++;
    }
  }
}

When I passed a tag over the reader the output was:

Waiting for Card

CARD SERIAL: E298ABB9

I played around more with some more commands I found here:
Manual
Test document

I was especially interested in the “wallet functions”. IE how to initialize the wallet, how to deduct from it etc.

And then somehow I messed up… Whatever message I sent to the reader it immediately sent back 0xFF which means a general error. The state led was on but the mode led was always off… weird. Fortunately I got help in the Arduino forum.

The idea was to send the “factory defaults” command to the reader in different baud rates using the Uno’s serial interface. After I did that the mode led was still off and I was disappointed. I thought the module was dead.

But I just uploaded the RFID tag reader sketch up to the UNO and it worked again!

Here’s the code that sends the factory defaults command to the RFID module:

void setup() {
  // put your setup code here, to run once:
 pinMode(13, OUTPUT); 
  delay(1000);
  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);
}

void loop() {
  // put your main code here, to run repeatedly: 

  Serial.begin(2400);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

  Serial.begin(4800);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

   Serial.begin(9600);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

   Serial.begin(14400);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

   Serial.begin(19200);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

   Serial.begin(28800);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

    Serial.begin(38400);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

    Serial.begin(57600);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

    Serial.begin(115200);
  delay(1000);

  Serial.write(0xAB);
  Serial.write(0x02);
  Serial.write(0x0F);

  digitalWrite(13, HIGH);
  delay(1000);  
  digitalWrite(13, LOW);

}

2 thoughts on “Resetting a MF522 Serial 13.56MHZ RFID Reader/Writer to its defaults”

  1. Hi,

    I found your this post because I was having the same issue. Now I am able to read the cards Serial, but I am having some issues while trying to write them or read data… did you manage to get that working?

    1. Misael, unfortunately not. Tried using the wallet function but didn’t get it working. So I am thinking to set up a web service that deals with the access control.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>