I'm using RFID library to read/write to NFC tags. I can read Ultralight tags without problems, but writing always fails. This is the code:
#include <SPI.h>
#include <MFRC522.h>#define RST_PIN 5
#define SS_PIN 53MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;// Show some details of the PICC (that is: the tag/card)
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));//data to write
uint8_t pageAddr = 0x08;byte dataBlock_16[] = {
0x01, 0x02, 0x03, 0x04,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};byte dataBlock_4[] = {
0x01, 0x02, 0x03, 0x04
};MFRC522::StatusCode status;
status = (MFRC522::StatusCode) mfrc522.MIFARE_Write(pageAddr, dataBlock_16, 16);
if (status != MFRC522::STATUS_OK) {
Serial.print(F("MIFARE_Write() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
} else Serial.println("success");}
void loop() {
}
This fails as well:
#include <SPI.h>
#include <MFRC522.h>#define RST_PIN 5
#define SS_PIN 53MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
return;// Show some details of the PICC (that is: the tag/card)
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));//data to write
uint8_t pageAddr = 0x08;byte dataBlock_16[] = {
0x01, 0x02, 0x03, 0x04,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};byte dataBlock_4[] = {
0x01, 0x02, 0x03, 0x04
};MFRC522::StatusCode status;
status = (MFRC522::StatusCode) mfrc522.MIFARE_Ultralight_Write(pageAddr, dataBlock_4, 4);
if (status != MFRC522::STATUS_OK) {
Serial.print(F("MIFARE_Write() failed: "));
Serial.println(mfrc522.GetStatusCodeName(status));
} else Serial.println("success");}
void loop() {
}
I'm always getting same error:
MIFARE_Write() failed: Timeout in communication.
Has anyone successfully written data to ultralight tags using RC522 module? I would really like to know how.