Skip to content

Commit

Permalink
Merge pull request #20 from ElectronicCats/NewExamples
Browse files Browse the repository at this point in the history
Add support for ISO15693 and ISO1443-3A
  • Loading branch information
sabas1080 authored Nov 8, 2020
2 parents b9822d7 + 7ee2de4 commit 2a03531
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 12 deletions.
6 changes: 3 additions & 3 deletions examples/DetectTags/DetectTags.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/

#include "Electroniccats_PN7150.h"
#define PN7150_IRQ (8)
#define PN7150_VEN (7)
#define PN7150_IRQ (15)
#define PN7150_VEN (14)
#define PN7150_ADDR (0x28)

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28
Expand Down Expand Up @@ -124,7 +124,7 @@ void displayCardInfo(RfIntf_t RfIntf){ //Funtion in charge to show the card/s in
}

void setup(){
Serial.begin(115200);
Serial.begin(9600);
while(!Serial);
Serial.println("Detect NFC tags with PN7150");

Expand Down
6 changes: 3 additions & 3 deletions examples/DetectingReaders/DetectingReaders.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/

#include "Electroniccats_PN7150.h"
#define PN7150_IRQ (8)
#define PN7150_VEN (7)
#define PN7150_IRQ (15)
#define PN7150_VEN (14)
#define PN7150_ADDR (0x28)

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28
Expand All @@ -24,7 +24,7 @@ unsigned char STATUSOK[] = {0x90, 0x00}, Cmd[256], CmdSize;
uint8_t mode = 2; // modes: 1 = Reader/ Writer, 2 = Emulation

void setup(){
Serial.begin(115200);
Serial.begin(9600);
while(!Serial);
Serial.println("Detect NFC readers with PN7150");
Serial.println("Initializing...");
Expand Down
138 changes: 138 additions & 0 deletions examples/ISO14443-3A_read_block/ISO14443-3A_read_block.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* Example to read a ISO14443-3A(Tag Type 2 - T2T) block 5 and show its information
* Authors:
* Salvador Mendoza - @Netxing - salmg.net
* For Electronic Cats - electroniccats.com
*
* November 2020
*
* This code is beerware; if you see me (or any other collaborator
* member) at the local, and you've found our code helpful,
* please buy us a round!
* Distributed as-is; no warranty is given.
*/

#include "Electroniccats_PN7150.h"
#define PN7150_IRQ (15)
#define PN7150_VEN (14)
#define PN7150_ADDR (0x28)

#define BLK_NB_ISO14443_3A (5) //Block to be read it


Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28
RfIntf_t RfInterface; //Intarface to save data for multiple tags

uint8_t mode = 1; // modes: 1 = Reader/ Writer, 2 = Emulation

int ResetMode(){ //Reset the configuration mode after each reading
Serial.println("Re-initializing...");
nfc.ConfigMode(mode);
nfc.StartDiscovery(mode);
}

void PrintBuf(const byte * data, const uint32_t numBytes){ //Print hex data buffer in format
uint32_t szPos;
for (szPos=0; szPos < numBytes; szPos++){
Serial.print(F("0x"));
// Append leading 0 for small values
if (data[szPos] <= 0xF)
Serial.print(F("0"));
Serial.print(data[szPos]&0xff, HEX);
if ((numBytes > 1) && (szPos != numBytes - 1))
Serial.print(F(" "));
}
Serial.println();
}

void PCD_ISO14443_3A_scenario (void){
bool status;
unsigned char Resp[256];
unsigned char RespSize;
/* Read block */
unsigned char ReadBlock[] = {0x30, BLK_NB_ISO14443_3A};

status = nfc.ReaderTagCmd(ReadBlock, sizeof(ReadBlock), Resp, &RespSize);
if((status == NFC_ERROR) || (Resp[RespSize-1] != 0x00)){
Serial.print("Error reading block: ");
Serial.print(ReadBlock[1],HEX);
Serial.print(" with error: ");
Serial.print(Resp[RespSize-1],HEX);
return;
}
Serial.print("------------------------Block ");
Serial.print(BLK_NB_ISO14443_3A, HEX);
Serial.println("-------------------------");
PrintBuf(Resp, 4);
}

void setup(){
Serial.begin(9600);
while(!Serial);
Serial.println("Read ISO14443-3A(T2T) data block 5 with PN7150");

Serial.println("Initializing...");
if (nfc.connectNCI()) { //Wake up the board
Serial.println("Error while setting up the mode, check connections!");
while (1);
}

if (nfc.ConfigureSettings()) {
Serial.println("The Configure Settings failed!");
while (1);
}

if(nfc.ConfigMode(mode)){ //Set up the configuration mode
Serial.println("The Configure Mode failed!!");
while (1);
}
nfc.StartDiscovery(mode); //NCI Discovery mode
Serial.println("Waiting for an ISO14443-3A Card ...");
}

void loop(){
if(!nfc.WaitForDiscoveryNotification(&RfInterface)){ // Waiting to detect cards
switch(RfInterface.Protocol) {
case PROT_T2T:
Serial.println(" - Found ISO14443-3A(T2T) card");
switch(RfInterface.ModeTech) { //Indetify card technology
case (MODE_POLL | TECH_PASSIVE_NFCA):
char tmp[16];
Serial.print("\tSENS_RES = ");
sprintf(tmp, "0x%.2X",RfInterface.Info.NFC_APP.SensRes[0]);
Serial.print(tmp); Serial.print(" ");
sprintf(tmp, "0x%.2X",RfInterface.Info.NFC_APP.SensRes[1]);
Serial.print(tmp); Serial.println(" ");

Serial.print("\tNFCID = ");
PrintBuf(RfInterface.Info.NFC_APP.NfcId, RfInterface.Info.NFC_APP.NfcIdLen);

if(RfInterface.Info.NFC_APP.SelResLen != 0) {
Serial.print("\tSEL_RES = ");
sprintf(tmp, "0x%.2X",RfInterface.Info.NFC_APP.SelRes[0]);
Serial.print(tmp); Serial.println(" ");
}
break;
}
PCD_ISO14443_3A_scenario();
break;

default:
Serial.println(" - Found a card, but it is not ISO14443-3A(T2T)!");
break;
}

//* It can detect multiple cards at the same time if they use the same protocol
if(RfInterface.MoreTags) {
nfc.ReaderActivateNext(&RfInterface);
}
//* Wait for card removal
nfc.ProcessReaderMode(RfInterface, PRESENCE_CHECK);
Serial.println("CARD REMOVED!");

nfc.StopDiscovery();
nfc.StartDiscovery(mode);
}
ResetMode();
delay(500);
}
154 changes: 154 additions & 0 deletions examples/ISO14443-3A_write_block/ISO14443-3A_write_block.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* Example to write a ISO14443-3A(Tag Type 2 - T2T) block 5 and show its information
* Authors:
* Salvador Mendoza - @Netxing - salmg.net
* For Electronic Cats - electroniccats.com
*
* November 2020
*
* This code is beerware; if you see me (or any other collaborator
* member) at the local, and you've found our code helpful,
* please buy us a round!
* Distributed as-is; no warranty is given.
*/

#include "Electroniccats_PN7150.h"
#define PN7150_IRQ (15)
#define PN7150_VEN (14)
#define PN7150_ADDR (0x28)

#define BLK_NB_ISO14443_3A (5) //Block to be read it
#define DATA_WRITE_ISO14443_3A 0x11, 0x22, 0x33, 0x44 //Data to write

Electroniccats_PN7150 nfc(PN7150_IRQ, PN7150_VEN, PN7150_ADDR); // creates a global NFC device interface object, attached to pins 7 (IRQ) and 8 (VEN) and using the default I2C address 0x28
RfIntf_t RfInterface; //Intarface to save data for multiple tags

uint8_t mode = 1; // modes: 1 = Reader/ Writer, 2 = Emulation

int ResetMode(){ //Reset the configuration mode after each reading
Serial.println("Re-initializing...");
nfc.ConfigMode(mode);
nfc.StartDiscovery(mode);
}

void PrintBuf(const byte * data, const uint32_t numBytes){ //Print hex data buffer in format
uint32_t szPos;
for (szPos=0; szPos < numBytes; szPos++){
Serial.print(F("0x"));
// Append leading 0 for small values
if (data[szPos] <= 0xF)
Serial.print(F("0"));
Serial.print(data[szPos]&0xff, HEX);
if ((numBytes > 1) && (szPos != numBytes - 1))
Serial.print(F(" "));
}
Serial.println();
}

void PCD_ISO14443_3A_scenario (void){
bool status;
unsigned char Resp[256];
unsigned char RespSize;
/* Read block */
unsigned char ReadBlock[] = {0x30, BLK_NB_ISO14443_3A};
/* Write block */
unsigned char WriteBlock[] = {0xA2, BLK_NB_ISO14443_3A, DATA_WRITE_ISO14443_3A};

// Write
status = nfc.ReaderTagCmd(WriteBlock, sizeof(WriteBlock), Resp, &RespSize);
if((status == NFC_ERROR) || (Resp[RespSize-1] != 0))
{
Serial.print("Error writing block: ");
Serial.print(ReadBlock[1],HEX);
Serial.print(" with error: ");
Serial.print(Resp[RespSize-1],HEX);
return;
}
Serial.print("Wrote: ");
Serial.println(WriteBlock[1]);

//Read block
status = nfc.ReaderTagCmd(ReadBlock, sizeof(ReadBlock), Resp, &RespSize);
if((status == NFC_ERROR) || (Resp[RespSize-1] != 0x00)){
Serial.print("Error reading block: ");
Serial.print(ReadBlock[1],HEX);
Serial.print(" with error: ");
Serial.print(Resp[RespSize-1],HEX);
return;
}
Serial.print("------------------------Block ");
Serial.print(BLK_NB_ISO14443_3A, HEX);
Serial.println("-------------------------");
PrintBuf(Resp, 4);
}

void setup(){
Serial.begin(9600);
while(!Serial);
Serial.println("Write ISO14443-3A(T2T) data block 5 with PN7150");

Serial.println("Initializing...");
if (nfc.connectNCI()) { //Wake up the board
Serial.println("Error while setting up the mode, check connections!");
while (1);
}

if (nfc.ConfigureSettings()) {
Serial.println("The Configure Settings failed!");
while (1);
}

if(nfc.ConfigMode(mode)){ //Set up the configuration mode
Serial.println("The Configure Mode failed!!");
while (1);
}
nfc.StartDiscovery(mode); //NCI Discovery mode
Serial.println("Waiting for an ISO14443-3A Card ...");
}

void loop(){
if(!nfc.WaitForDiscoveryNotification(&RfInterface)){ // Waiting to detect cards
switch(RfInterface.Protocol) {
case PROT_T2T:
Serial.println(" - Found ISO14443-3A(T2T) card");
switch(RfInterface.ModeTech) { //Indetify card technology
case (MODE_POLL | TECH_PASSIVE_NFCA):
char tmp[16];
Serial.print("\tSENS_RES = ");
sprintf(tmp, "0x%.2X",RfInterface.Info.NFC_APP.SensRes[0]);
Serial.print(tmp); Serial.print(" ");
sprintf(tmp, "0x%.2X",RfInterface.Info.NFC_APP.SensRes[1]);
Serial.print(tmp); Serial.println(" ");

Serial.print("\tNFCID = ");
PrintBuf(RfInterface.Info.NFC_APP.NfcId, RfInterface.Info.NFC_APP.NfcIdLen);

if(RfInterface.Info.NFC_APP.SelResLen != 0) {
Serial.print("\tSEL_RES = ");
sprintf(tmp, "0x%.2X",RfInterface.Info.NFC_APP.SelRes[0]);
Serial.print(tmp); Serial.println(" ");
}
break;
}
PCD_ISO14443_3A_scenario();
break;

default:
Serial.println(" - Found a card, but it is not ISO14443-3A(T2T)!");
break;
}

//* It can detect multiple cards at the same time if they use the same protocol
if(RfInterface.MoreTags) {
nfc.ReaderActivateNext(&RfInterface);
}
//* Wait for card removal
nfc.ProcessReaderMode(RfInterface, PRESENCE_CHECK);
Serial.println("CARD REMOVED!");

nfc.StopDiscovery();
nfc.StartDiscovery(mode);
}
ResetMode();
delay(500);
}
Loading

0 comments on commit 2a03531

Please sign in to comment.