We will use Arduino as the host controller to interface with RC522 RFID Module and write data to RFID card. I already made a tutorial on how to interface RC522 RFID Module with Arduino. Check out that tutorial before proceeding further as there are some basics related to RFID Communication, MFRC522 IC, RC522 RFID Module and more.

A Brief Look at Memory Map of MIFARE 1K Tag

If you upload the ‘DumpInfo’ example and open the serial monitor, Arduino will print all the contents of the MIFARE 1K RFID Tag on the serial monitor after scanning it properly. It is very important to understand the memory layout of the RFID Tag as we will know what is the significance of each memory location, what memory locations are reserved and what locations are free to use for storing user data. The following image is a screen shot of the serial monitor output of ‘DumpInfo’ example. Let us now analyze this.

Analyzing Serial Monitor Output

The first line shows the firmware version of the MFRC522 IC. In this case, the result is 0x92. Here, ‘9’ stands for MFRC522 IC and ‘2’ stands for software version 2.0. After scanning the RFID Card, we get the UID, SAK and Type of RFID tag. In this case, the UID is ‘6C 08 88 17’, SAK is ‘08’ and the type of card is MIFARE 1K.

Next, you can see the actual memory dump of the MIFARE 1K Tag. A typical MIFARE 1K RFID tag has 1K Byte of memory organized into 16 Sectors (Sector 0 to Sector 15). Each Sector consists of 4 Blocks.

Understanding memory Map of MIFARE 1K Tag

For example, Sector 0 has Blocks 0, 1, 2 and 3. Sector 1 has Blocks 4, 5, 6 and 7 and so on and finally Sector 15 has Blocks 60, 61, 62 and 63. Each Block can store 16 Bytes of data. NOTE: This numbering is just to understand the memory layout. So, 16 Sectors * 4 Blocks * 16 Bytes = 1024 Bytes = 1K

Block 0 of Sector 0 is reserved for storing Manufacturer Data. Usually, this Block contains 4 Byte UID (Unique ID) in case of MIFARE 1K Tags (and also MIFARE 4K, MIFARE Mini tags from NXP). Advanced Tags like MIFARE Plus, MIFARE Ultralight, MIFARE DESFire consists of a 7 Byte UID.

Each Sector consists of three Data Blocks, which can be used for storing user data. The last Block of each Sector i.e., Block 3 in case of Sector 0, Block 7 in case of Sector 1 and so on is known as Sector Trailer. As there are 16 Sectors, there are 16 Sector Trailers. Each Sector Trailer consists of the following information:

A mandatory 6 Byte Key A. 4 Bytes for Access Bits. Optional 6 Byte Key B (if not used, data can be stored).

NOTE: Byte 9 in the ‘Access Bits’ region is available for user data. NOTE: All sectors have three data blocks and one sector trailer except sector 0. It has one block (Block 0) reserved for Manufacturer Data. So, Sector 0 has two data blocks and one sector trailer.

The Access Bits in the Sector Trailer determine the access conditions for all the blocks of a Sector. 3-bits are needed for specifying access conditions for the three data blocks and the sector trailer. The access condition includes Read, Write, Increment, Decrement, Transfer and Restore.

With all this information, we can conclude that, you can store 47 Bytes of Data in a MIFARE 1K RFID Data. Let us now see how to Write Data to RFID Tag using Arduino and RC522 RFID Module.

Interfacing RC522 with Arduino

Even though MFRC522 IC supports three types of Serial Communication; UART, SPI and I2C, the SPI Interface is the fastest and most common. The following image shows the pinout of RC522 RFID Module.

For reliable communication between Arduino and RC522, let us use the Hardware SPI Pins. The following table shows the connections between Arduino and RC522 Module.

Components Required

Arduino UNO RC522 RFID Reader / Writer Module MIFARE 1K RFID Tag Connecting Wires

Circuit Diagram

The following image shows the connections between Arduino and RC522 RFID Module.

Write Data to RFID Card

I wrote a simple program in which I write data to 1 Block (Block 2) and fill it completely. This means, the length of the data should be 16 Bytes.

Code

The Arduino code for writing data in to MIFARE 1K RFID Tag is given below. I commented the code so that you can understand it easily.

Conclusion

A simple demonstration on how to Write Data to RFID card using RC522 RFID Reader / Write Module and Arduino UNO. You learned the memory layout of MIFARE Classic 1K RFID Tags, memory locations feasible to write data and also write some random text to an RFID Card. Thanks. Comment * Name * Email * Website

Δ

How to Write Data to RFID Card using RC522 RFID Module  - 1How to Write Data to RFID Card using RC522 RFID Module  - 68How to Write Data to RFID Card using RC522 RFID Module  - 44How to Write Data to RFID Card using RC522 RFID Module  - 18How to Write Data to RFID Card using RC522 RFID Module  - 9How to Write Data to RFID Card using RC522 RFID Module  - 45How to Write Data to RFID Card using RC522 RFID Module  - 31How to Write Data to RFID Card using RC522 RFID Module  - 95How to Write Data to RFID Card using RC522 RFID Module  - 72How to Write Data to RFID Card using RC522 RFID Module  - 35How to Write Data to RFID Card using RC522 RFID Module  - 69How to Write Data to RFID Card using RC522 RFID Module  - 39How to Write Data to RFID Card using RC522 RFID Module  - 98How to Write Data to RFID Card using RC522 RFID Module  - 2How to Write Data to RFID Card using RC522 RFID Module  - 43How to Write Data to RFID Card using RC522 RFID Module  - 98How to Write Data to RFID Card using RC522 RFID Module  - 86How to Write Data to RFID Card using RC522 RFID Module  - 32