RC522 Not working

I purchased the RC522 RFID reader from Amazon. I connected the pins as per the table given. I used the dumpinfo example. It does not read the tag information and the output got is shown here. I used the RFID tags supplied along with the reader. Why is it not working?

image

image

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

#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above

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

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
//mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
}

void loop() {
// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
if ( ! mfrc522.PICC_IsNewCardPresent()) {
//Serial.println("A");
return;
}

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
Serial.println("B");
	return;
}

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

}

When I traced the program, I came to know that the if condition for "Select one of the cards" is not all executed even if the tag is brought near to the reader.

I get the output in the serial monitor as

Firmware Version: 0x92 = v2.0
Scan PICC to see UID, SAK, type, and data blocks...
So, I think the reader reads something.
I think pins 9, 10 are used properly.
How to know that MISO & MOSI and other pins are properly configured in the code given? The code is available in the dumpinfo example .

Why not post your code, in code tags, instead of an unreadable image?

Post a wiring diagram and a picture of your wired project as well as any product links and spec sheets.

Ehh.... Code tags. Select the autoformatted code in the IDE. Then click the code tag symbol, </> and paste.
That makes it easy for helpers to copy, compile, etc the code.

/*
   --------------------------------------------------------------------------------------------------------------------
   Example sketch/program showing how to read data from a PICC to serial.
   --------------------------------------------------------------------------------------------------------------------
   This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid

   Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
   Reader on the Arduino SPI interface.

   When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
   then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
   you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
   will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
   when removing the PICC from reading distance too early.

   If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
   So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
   details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
   keep the PICCs at reading distance until complete.

   @license Released into the public domain.

   Typical pin layout used:
   -----------------------------------------------------------------------------------------
               MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
               Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
   Signal      Pin          Pin           Pin       Pin        Pin              Pin
   -----------------------------------------------------------------------------------------
   RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
   SPI SS      SDA(SS)      10            53        D10        10               10
   SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
   SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
   SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
*/

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

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

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

void setup() {
  Serial.begin(9600);		// Initialize serial communications with the PC
  while (!Serial);		// Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();			// Init SPI bus
  mfrc522.PCD_Init();		// Init MFRC522
  delay(4);				// Optional delay. Some board do need more time after init to be ready, see Readme
  mfrc522.PCD_DumpVersionToSerial();	// Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  //mfrc522.PCD_SetAntennaGain(mfrc522.RxGain_max);
}

void loop() {
  // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    //Serial.println("A");
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    Serial.println("B");
    return;
  }

  // Dump debug info about the card; PICC_HaltA() is automatically called
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

What sort of Arduino have you got?
If it is a 5V one like a Uno or original nano then you can’t connect it directly and expect it to work. This is because the readers signals are only 3V3 and the Arduino is expecting and producing 5V signals.

1 Like

@kkthyagharajan your other topic asking for help to debug an RC522 sketch has been closed. It had only one reply and that was asking you to post your code

Why did you open a second topic ?

I am using UNO PLUS. I am using 3.3V pin of UNO PLUS to power the RC522. The GND signal of UNO and RC522 are connected. Then I have connected the other pins of RC522 as shown above. I have connected the UNO PLUS to the USB port of my laptop. I have installed Arduino RFID library for MFRC522 (SPI) from GitHub. The above code is an example given in that. Many YouTube tutorials connect the RC522 pins directly to the Arduino pins. Should I use 5V to 3.3V converter in this case?

Yes and many YouTube videos are done by idiots who don't know what they are doing and only manage to function by the skin of their teeth. A slight change in thongs like the voltage out of the regulator can push them over the edge into not working.

Well I would, the clock and data are 5V signals going into a 3V3 device so you should convert them with a 510R and 1K resistor. You need the values to be low so that stray capacitance does not slow down the edges of the signal. So many examples on line have the ratios of the resistors correct but the absolute values way too high.

The MISO signal is a signal that is theoretically too small to meet the minimum requirements for a 5V system, but sometimes it works. But if not use two of the six buffers you get in a 74HCT14 chip to get a good signal.

Do not be tempted to use a "bidirectional level shifter board" because these are designed for I2C and are very flaky when used at SPI speeds.

Does the functioning of the RC522 depend on the microcontroller frequency or type of the Arduino board used? Should the frequency of communication be adjusted in the code? The example code provided in GitHub - miguelbalboa/rfid: Arduino RFID Library for MFRC522 does not provide a clear idea about what is in the header files. Since RC522 uses 13.5 MHz if the microcontroller model changes the frequency will also change and I think the program should also be changed. But there is no clue provided there.

Yes, it is set in the code.

No.

You are mixing up the frequency of operation of the frequency of the interface.
The interface is SPI, and that frequency is set when you set up the SPI interface, normally this will be 1MHz but the RC522 can probably cope with a lot faster than this. See the RC522 data sheet for the actual figure. With SPI the reader is a slave and it takes its transfer clock frequency from the Arduino.

To be strictly accurate a 13.5 MHz reader sends out data to the card at 13.5MHz as you might expect, but the tag sends data back to the reader at a quarter of this frequency. Not that it matters if you just want to use it as the RC522 takes care of all that. On the RC522 board as opposed to the chip itself there will be a crystal oscillator that drives it.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.