This program is for reading and writing from /to MIFARE Classic 1k ,MIFARE Ultralight MF0ICU1,MIFARE Ultralight NTAG213,MIFARE Ultralight NTAG203
Diff: main.cpp
- Revision:
- 3:f9ed412458d5
- Parent:
- 2:e27413743e1b
- Child:
- 4:9d923c6e6c14
--- a/main.cpp Thu May 25 07:16:28 2017 +0000
+++ b/main.cpp Fri May 26 09:57:55 2017 +0000
@@ -1,14 +1,27 @@
-//Test of cheap 13.56Mhz RFID-RC522 module
-//Connect as follows:
-//RFID pins -> WIZWiki-W7500 header CN5 (Arduino-compatible header)
-//----------------------------------------
-//1.RFID IRQ -> Not used. Leave open
-//2.RFID MISO -> WIZWiki-W7500 SPI_MISO =D12
-//3.RFID MOSI -> WIZWiki-W7500 SPI_MOSI =D11
-//4.RFID SCK -> WIZWiki-W7500 SPI_SCK =D13
-//5.RFID SDA -> WIZWiki-W7500 SPI_CS =D10
-//6.RFID RST -> WIZWiki-W7500 =D9
-//3.3V and Gnd to the respective pins
+/*--------------------------------------------------------Reading Writing MIFARE Tags---------------------------------------------------------------
+Note:
+---------
+1.This program is for reading and writing from /to MIFARE Classic 1k ,MIFARE Ultralight MF0ICU1,MIFARE Ultralight NTAG213,MIFARE Ultralight NTAG203
+2.Generally we are using MBED model WIZnet WIZWiki W7500 to interfacng with MFRC522 Rader and writer device using SPI protocol
+3.This program is designed such a way that it will take input 1,2 for reading or writing from/to tags
+4.Once user can entering input based on input it will call read and write function respectively...
+----------------------------------------------------------------------------------------------------------------------------------------------------*/
+
+
+
+/*Test of cheap 13.56Mhz RFID-RC522 module
+Connect as follows:
+RFID pins -> WIZWiki-W7500 header CN5 (Arduino-compatible header)
+--------------------------------------------------------------------------
+1.RFID IRQ -> Not used. Leave open
+2.RFID MISO -> WIZWiki-W7500 SPI_MISO =D12
+3.RFID MOSI -> WIZWiki-W7500 SPI_MOSI =D11
+4.RFID SCK -> WIZWiki-W7500 SPI_SCK =D13
+5.RFID SDA -> WIZWiki-W7500 SPI_CS =D10
+6.RFID RST -> WIZWiki-W7500 =D9
+3.3V and Gnd to the respective pins*/
+
+
//Adding Library for Mbed
@@ -17,7 +30,10 @@
#include "MFRC522.h"
//Adding Library for SPI protocol
#include "SPI.h"
+
+//Define RFID version and date
#define VERSION "RFID_2017_03_20"
+//Define board
#define CIBLE "WIZwiki-W7500"
@@ -30,21 +46,23 @@
// WIZWiki-W7500 Pin for MFRC522 reset(pick another D pin if you need D8)
#define MF_RESET D9
+
+//Define led for identification
DigitalOut LedGreen(D7);
-DigitalOut LedRed(D6);
-DigitalOut LedYellow(D5);
-char save[1024];
+
//Serial connection to PC for output
Serial pc(USBTX, USBRX);
+
+//Define or create MFRC522 class and passing pins as arguments
MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);
//* Local functions */
-void DumpMifareClassicToSerial (MFRC522::Uid *uid, uint8_t piccType, MFRC522::MIFARE_Key *key);
-void DumpMifareClassicSectorToSerial(MFRC522::Uid *uid, MFRC522::MIFARE_Key *key, uint8_t sector);
-void DumpMifareUltralightToSerial (void);
-void writeDataUL(void);
-void writeDataClassic1k(void);
+void DumpMifareClassicToSerial (MFRC522::Uid *uid, uint8_t piccType, MFRC522::MIFARE_Key *key); //It is reading MIFARE Classic 1k memory block and sector
+void DumpMifareClassicSectorToSerial(MFRC522::Uid *uid, MFRC522::MIFARE_Key *key, uint8_t sector); //It is reading MIFARE Classic 1k memory block data and sector data
+void DumpMifareUltralightToSerial (void); //It is reading MIFARE Ultralight memory block,block data and sector,sector data
+void writeDataUL(void); //It is Writing function to MIFARE Ultralight
+void writeDataClassic1k(void); //It is Writing function to MIFARE Classic 1k
uint8_t page;
/**
* Dumps debug info about the selected PICC to Serial.
@@ -54,6 +72,7 @@
void DumpToSerial(MFRC522::Uid *uid)
{
+ //Declaring MIFARE Classic 1k key
MFRC522::MIFARE_Key key;
// Print Card UID
@@ -77,30 +96,22 @@
for (uint8_t i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
+ //Calling MIFARE Classic 1k memory block and sector
DumpMifareClassicToSerial(uid, piccType, &key);
break;
case MFRC522::PICC_TYPE_MIFARE_UL:
+ //Calling MIFARE Ultralight memory block,block data and sector,sector data
DumpMifareUltralightToSerial();
break;
- case MFRC522::PICC_TYPE_TNP3XXX:
- printf("Dumping memory contents not implemented for that PICC type. \n\r");
- break;
- case MFRC522::PICC_TYPE_ISO_14443_4:
- case MFRC522::PICC_TYPE_ISO_18092:
- case MFRC522::PICC_TYPE_MIFARE_PLUS:
- printf("Dumping memory contents not implemented for that PICC type. \n\r");
- break;
- case MFRC522::PICC_TYPE_UNKNOWN:
- case MFRC522::PICC_TYPE_NOT_COMPLETE:
default:
break; // No memory dump here
}
printf("\n\r");
- RfChip.PICC_HaltA(); // Already done if it was a MIFARE Classic PICC.
+ RfChip.PICC_HaltA(); // Instructs a PICC in state ACTIVE(*) to go to state HALT.
} // End PICC_DumpToSerial()
/**
@@ -154,10 +165,10 @@
*/
void DumpMifareClassicSectorToSerial(MFRC522::Uid *uid, MFRC522::MIFARE_Key *key, uint8_t sector)
{
- uint8_t status;
- uint8_t firstBlock; // Address of lowest address to dump actually last block dumped)
- uint8_t no_of_blocks; // Number of blocks in sector
- bool isSectorTrailer; // Set to true while handling the "last" (ie highest address) in the sector.
+ uint8_t status; // Set what type of error is found
+ uint8_t firstBlock; // Address of lowest address to dump actually last block dumped)
+ uint8_t no_of_blocks; // Number of blocks in sector
+ bool isSectorTrailer; // Set to true while handling the "last" (ie highest address) in the sector.
// The access bits are stored in a peculiar fashion.
// There are four groups:
@@ -189,9 +200,9 @@
}
// Dump blocks, highest address first.
- uint8_t byteCount;
- uint8_t buffer[18];
- uint8_t blockAddr;
+ uint8_t byteCount; //No of reading data
+ uint8_t buffer[18]; //Reading data of buffer
+ uint8_t blockAddr; // No of Sector
isSectorTrailer = true;
for (int8_t blockOffset = no_of_blocks - 1; blockOffset >= 0; blockOffset--) {
blockAddr = firstBlock + blockOffset;
@@ -207,6 +218,7 @@
printf(" %3d ", blockAddr);
// Establish encrypted communications before reading the first block
+ /*While MFRC522 reader/writer is not uthenticate MIFARE card then it will through PCD_Authenticate() failed: Timeout in communication */
if (isSectorTrailer) {
status = RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, firstBlock, key, uid);
if (status != MFRC522::STATUS_OK) {
@@ -216,6 +228,7 @@
}
// Read block
+ /*If MFRC522 reader/writer is uthenticate MIFARE card but it not uthenticate key then it will through MIFARE_Read() failed: Timeout in communication */
byteCount = sizeof(buffer);
status = RfChip.MIFARE_Read(blockAddr, buffer, &byteCount);
if (status != MFRC522::STATUS_OK) {
@@ -228,6 +241,9 @@
printf(" %2X", buffer[index]);
}
+
+//This block is printing access bit......................................................................................
+
// Parse sector trailer data
if (isSectorTrailer) {
c1 = buffer[7] >> 4;
@@ -270,6 +286,9 @@
buffer[1],
buffer[0]);
}
+
+ //END....................................................................................................................
+
printf("\n\r");
}
@@ -281,14 +300,15 @@
*/
void DumpMifareUltralightToSerial(void)
{
- uint8_t status;
- uint8_t byteCount;
- uint8_t buffer[18];
+ uint8_t status; // Set what type of error is found
+ uint8_t byteCount; //No of reading data
+ uint8_t buffer[18]; //Reading data from buffer
uint8_t i;
printf("Page 0 1 2 3 \n");
// Try the mpages of the original Ultralight. Ultralight C has more pages.
for ( page = 0; page < 16; page +=4) {
// Read pages
+ /*If MFRC522 reader/writer is uthenticate MIFARE card but it not uthenticate key then it will through MIFARE_Read() failed: Timeout in communication */
byteCount = sizeof(buffer);
status = RfChip.MIFARE_Read(page, buffer, &byteCount);
if (status != MFRC522::STATUS_OK) {
@@ -344,26 +364,12 @@
case MFRC522::PICC_TYPE_MIFARE_UL:
writeDataUL();
break;
- case MFRC522::PICC_TYPE_TNP3XXX:
- printf("Dumping memory contents not implemented for that PICC type. \n\r");
- break;
- case MFRC522::PICC_TYPE_ISO_14443_4:
- case MFRC522::PICC_TYPE_ISO_18092:
- case MFRC522::PICC_TYPE_MIFARE_PLUS:
- printf("Dumping memory contents not implemented for that PICC type. \n\r");
- break;
-
- case MFRC522::PICC_TYPE_UNKNOWN:
- case MFRC522::PICC_TYPE_NOT_COMPLETE:
default:
break; // No memory dump here
}
-
printf("\n\r");
-
}
-
void writeDataClassic1k()
{
//Declaration of MFRC522 key
@@ -375,21 +381,11 @@
while(true) {
-
+
+ // All keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (uint8_t i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
- // Look for new cards
- if ( ! RfChip.PICC_IsNewCardPresent()) {
- continue;
- }
-
- // Select one of the cards
- if ( ! RfChip.PICC_ReadCardSerial()) {
- continue;
- }
- printf("\n\r");
-
pc.printf("Enter 1 block: "); // Enter Data
@@ -398,13 +394,13 @@
}
printf("\n\r");
block = 1;
-
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
// Write block
@@ -412,7 +408,7 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow = 1;
+
continue;
} else {
LedGreen=1;
@@ -426,12 +422,13 @@
}
printf("\n\r");
block = 2;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
// Write block
@@ -439,7 +436,7 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow = 1;
+
continue;
} else {
LedGreen = 1;
@@ -453,12 +450,13 @@
}
printf("\n\r");
block = 4;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
// Write block
@@ -466,7 +464,7 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow = 1;
+
continue;
} else {
LedGreen = 1;
@@ -480,12 +478,13 @@
}
printf("\n\r");
block = 5;
+ /*While MFRC522 reader/writer is not uthenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -494,7 +493,7 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen = 1;
@@ -508,12 +507,13 @@
}
printf("\n\r");
block = 6;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
// Write block
@@ -521,7 +521,7 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen=1;
@@ -535,12 +535,13 @@
}
printf("\n\r");
block = 8;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -549,37 +550,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
- pc.printf("Succesfully Written to tag: ");
- }
- printf("\n\r");
- pc.printf("Enter 9 block: "); // Enter Data
- for(uint8_t i = 0; i < 16; i++) {
- buffer[i] = pc.putc(pc.getc());
- }
- printf("\n\r");
- block = 9;
- pc.printf("Authenticating using key A...");
- status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
- if (status != MFRC522::STATUS_OK) {
- pc.printf("PCD_Authenticate() failed: ");
- pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
- continue;
- }
- // Write block
- status = (MFRC522::StatusCode)RfChip.MIFARE_Write(block, buffer, 16);
- if (status != MFRC522::STATUS_OK) {
- pc.printf("MIFARE_Write() failed: ");
- pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
- continue;
- } else {
- LedYellow=1;
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -589,12 +563,13 @@
}
printf("\n\r");
block = 10;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -603,10 +578,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -616,12 +591,13 @@
}
printf("\n\r");
block = 12;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -630,10 +606,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -643,12 +619,13 @@
}
printf("\n\r");
block = 13;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -657,10 +634,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -670,12 +647,13 @@
}
printf("\n\r");
block = 14;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -684,10 +662,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
@@ -699,12 +677,13 @@
}
printf("\n\r");
block = 16;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -713,10 +692,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -726,12 +705,13 @@
}
printf("\n\r");
block = 17;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -740,10 +720,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -753,12 +733,13 @@
}
printf("\n\r");
block = 18;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -767,10 +748,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
@@ -781,12 +762,13 @@
}
printf("\n\r");
block = 20;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -795,10 +777,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -808,12 +790,13 @@
}
printf("\n\r");
block = 21;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -822,10 +805,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -835,12 +818,13 @@
}
printf("\n\r");
block = 22;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -849,10 +833,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -862,12 +846,13 @@
}
printf("\n\r");
block = 24;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -876,10 +861,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -889,12 +874,13 @@
}
printf("\n\r");
block = 25;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -903,10 +889,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -916,12 +902,13 @@
}
printf("\n\r");
block = 26;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -930,10 +917,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -943,12 +930,13 @@
}
printf("\n\r");
block = 28;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -957,10 +945,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -970,12 +958,13 @@
}
printf("\n\r");
block = 29;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -984,10 +973,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -997,12 +986,13 @@
}
printf("\n\r");
block = 30;
+ /*While MFRC522 reader/writer is not Authenticate MIFARE card key A then it will through PCD_Authenticate() failed: Timeout in communication */
pc.printf("Authenticating using key A...");
status = (MFRC522::StatusCode)RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(RfChip.uid));
if (status != MFRC522::STATUS_OK) {
pc.printf("PCD_Authenticate() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
}
@@ -1011,10 +1001,10 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedRed=1;
+
continue;
} else {
- LedYellow=1;
+
pc.printf("Succesfully Written to tag: ");
}
printf("\n\r");
@@ -1034,8 +1024,8 @@
{
//Declaration of MFRC522 status
MFRC522::StatusCode status;
- uint8_t buffer[16];
- uint8_t page;
+ uint8_t buffer[16]; //Define buffer
+ uint8_t page; //Define page
while(true) {
@@ -1051,7 +1041,7 @@
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen=1;
@@ -1067,11 +1057,12 @@
printf("\n\r");
page = 5;
// Write block
+ //While MFRC522 reader/writer is not Authenticate MIFARE card it will through MIFARE_Write() failed: Error in communication
status = (MFRC522::StatusCode)RfChip.MIFARE_UltralightWrite(page, buffer, 4);
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen=1;
@@ -1087,11 +1078,12 @@
printf("\n\r");
page = 6;
// Write block
+ //While MFRC522 reader/writer is not Authenticate MIFARE card it will through MIFARE_Write() failed: Error in communication
status = (MFRC522::StatusCode)RfChip.MIFARE_UltralightWrite(page, buffer, 4);
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen=1;
@@ -1107,11 +1099,12 @@
printf("\n\r");
page = 7;
// Write block
+ //While MFRC522 reader/writer is not Authenticate MIFARE card it will through MIFARE_Write() failed: Error in communication
status = (MFRC522::StatusCode)RfChip.MIFARE_UltralightWrite(page, buffer, 4);
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen=1;
@@ -1127,11 +1120,12 @@
printf("\n\r");
page = 8;
// Write block
+ //While MFRC522 reader/writer is not Authenticate MIFARE card it will through MIFARE_Write() failed: Error in communication
status = (MFRC522::StatusCode)RfChip.MIFARE_UltralightWrite(page, buffer, 4);
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen=1;
@@ -1147,11 +1141,12 @@
printf("\n\r");
page = 9;
// Write block
+ //While MFRC522 reader/writer is not Authenticate MIFARE card it will through MIFARE_Write() failed: Error in communication
status = (MFRC522::StatusCode)RfChip.MIFARE_UltralightWrite(page, buffer, 4);
if (status != MFRC522::STATUS_OK) {
pc.printf("MIFARE_Write() failed: ");
pc.printf(RfChip.GetStatusCodeName(status));
- LedYellow=1;
+
continue;
} else {
LedGreen=1;
@@ -1186,9 +1181,8 @@
while(true) {
- LedRed = 0;
+
LedGreen = 1;
- LedYellow = 0;
// Look for new cards
if ( ! RfChip.PICC_IsNewCardPresent()) {