Hello NFC enthusiasts,
The following topics will be covered in this document:
This document will be segmented into three parts:
- Description.
- Software configuration section.
- Hardware configuration section.
- Demonstration.
Description.
The purpose of this project is to copy the information stored from one tag to another by making use of GPIOs to decide which tag to copy from. This way, topics such as read and write NDEF, card activation and GPIOs will be implemented.

Software configuration section:
This demonstration is based on NXP NFC Reader Library v05.02.00, NfcrdlibEx3_NFCForum project for PNEV7462B, in which some modifications are going to be made in order to carry this out. These tags are compliant with NFC Forum Type 2 Tag and ISO/IEC14443 Type A specifications.
- In phacDiscLoop.h modify the max number of cards supported (two cards for this demonstration):
#define PHAC_DISCLOOP_CFG_MAX_CARDS_SUPPORTED 0x02U
- In NfcrdlibEx3_NFCForum.c add the following code in LoadDiscoveryConfiguration():
static phStatus_t LoadDiscoveryConfiguration()
{
...
/*Passive max typea devices*/
status = phacDiscLoop_SetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TYPEA_DEVICE_LIMIT, 2);
CHECK_STATUS(status);
}
A fix to the SW stack has to be made (Fix will be implemented in the next release):
open "phacDiscLoop_Sw_Int_A.c", line 511, change if statement as below.
if((pDataParams->sTypeATargetInfo.bTotalTagsFound > 1) && ((bTypeATagIdx) < pDataParams->sTypeATargetInfo.bTotalTagsFound))
- In NfcrdlibEx3_NFCForum.c add #include "phhalGpio.h" to local headers section.
#include <cards.h>
#include "phhalGpio.h"
#include "NfcrdlibEx3_NFCForum.h"
- In NfcrdlibEx3_NFCForum.c define uint16_t NDEFlength = 0 and declare void InitGPIOs(void) in Global Defines section.
phacDiscLoop_Sw_DataParams_t * pDiscLoop;
void * ppalI18092mPI;
void * ppalI18092mT;
void * palTop;
uint8_t bTagState1;
uint8_t* value;
uint8_t* value1;
uint8_t val,val1;
uint16_t NDEFlength = 0;
void InitGPIOs(void);
- in Main Function, initialize the following:
int main (void)
{
value=&val;
value1=&val1;
InitGPIOs();
- In case of multiple devices (which is of our interest) add the following code and comment the if(wNumberOfTags > 1){...} section as follows:
else if((status & PH_ERR_MASK) == PHAC_DISCLOOP_MULTI_DEVICES_RESOLVED)
{
DEBUG_PRINTF (" \n Multiple cards resolved: \n");
status = phacDiscLoop_GetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TECH_DETECTED, &wTagsDetected);
CHECK_STATUS(status);
status = phacDiscLoop_GetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_NR_TAGS_FOUND, &wNumberOfTags);
CHECK_STATUS(status);
DEBUG_PRINTF ("\tNumber of tags: %d \n",wNumberOfTags);
DEBUG_PRINTF ("\n Tag 1 NDEF information: \n");
status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x00);
status = phalTop_CheckNdef(palTop, &bTagState1);
DEBUG_ERROR_PRINT(status);
status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
DEBUG_ERROR_PRINT(status);
DEBUG_PRINTF ("\n Tag 2 NDEF information: \n");
status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x01);
status = phalTop_CheckNdef(palTop, &bTagState1);
DEBUG_ERROR_PRINT(status);
status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
DEBUG_ERROR_PRINT(status);
DEBUG_PRINTF (" \n --------------------------------------------------------------------------------------- \n\n");
DEBUG_PRINTF (" \n Options: \n\n");
DEBUG_PRINTF (" \n 1.- Left button -(X)-( )- To copy NDEF message from Tag 1 to Tag 2 \n\n");
DEBUG_PRINTF (" \n 2.- Right button -( )-(X)- To copy NDEF message from Tag 2 to Tag 1 \n\n");
DEBUG_PRINTF (" \n --------------------------------------------------------------------------------------- \n\n");
do
{
phhalPcr_GetGpioVal(2,value);
phhalPcr_GetGpioVal(3,value1);
}while(*value==1 && *value1==1);
if(*value==0 && *value1==1)
{
DEBUG_PRINTF (" \n Copy NDEF from Tag 1 to Tag 2 \n");
status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x00);
status = phalTop_CheckNdef(palTop, &bTagState1);
DEBUG_ERROR_PRINT(status);
status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
DEBUG_ERROR_PRINT(status);
status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x01);
status = phalTop_CheckNdef(palTop, &bTagState1);
DEBUG_ERROR_PRINT(status);
if(bTagState1 == PHAL_TOP_STATE_READWRITE)
{
status = WriteNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
DEBUG_ERROR_PRINT(status);
}
DEBUG_PRINTF (" \n NDEF from Tag 1 to Tag 2 already copied \n");
}
else if(*value==1 && *value1==0)
{
DEBUG_PRINTF (" \n Copy NDEF from Tag 2 to Tag 1 \n");
status = phalTop_CheckNdef(palTop, &bTagState1);
status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
DEBUG_ERROR_PRINT(status);
status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x00);
status = phalTop_CheckNdef(palTop, &bTagState1);
if(bTagState1 == PHAL_TOP_STATE_READWRITE)
{
status = WriteNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
DEBUG_ERROR_PRINT(status);
}
DEBUG_PRINTF (" \n NDEF from Tag 2 to Tag 1 already copied \n");
}
DEBUG_PRINTF (" \n Please remove the tags \n\n");
DEBUG_PRINTF (" \n Press any button to continue... \n\n");
do
{
phhalPcr_GetGpioVal(2,value);
phhalPcr_GetGpioVal(3,value1);
}while(*value==1 && *value1==1);
}
In NfcrdlibEx3_NFCForum.h declare WriteNdefMessage().
phStatus_t WriteNdefMessage(
uint8_t TopTagType);
In NfcrdlibEx3_NFCForum.c define the function WriteNdefMessage().
phStatus_t WriteNdefMessage(uint8_t TopTagType)
{
phStatus_t status;
uint8_t bTagState;
uint16_t wDataLength = 0;
status = phalTop_SetConfig(palTop, PHAL_TOP_CONFIG_TAG_TYPE, TopTagType);
DEBUG_ERROR_PRINT(status);
status = phalTop_CheckNdef(palTop, &bTagState);
DEBUG_ERROR_PRINT(status);
if(bTagState == PHAL_TOP_STATE_READWRITE)
{
status = phalTop_WriteNdef(palTop, baSnepAppBuffer, NDEFlength);
DEBUG_ERROR_PRINT(status);
if(NDEFlength)
{
DEBUG_PRINTF("\tNDEF detected...\n");
DEBUG_PRINTF("\tNDEF length: %d\n", wDataLength);
DEBUG_PRINTF("\tNDEF message:\n");
DumpBuffer(baSnepAppBuffer, 50);
}
else
{
DEBUG_PRINTF("\tNDEF content is NULL...\n");
}
}
else
{
DEBUG_PRINTF("\tNo NDEF content detected...\n");
}
return status;
}
In NfcrdlibEx3_NFCForum.c define InitGPIOs().
void InitGPIOs(void)
{
phhalPcr_ConfigInput(2,true,false,false,false,true,false);
phhalPcr_ConfigInput(3,true,false,false,false,true,false);
}
Hardware configuration section:
For the Hardware set up, two push buttons will be connected to GPIO_2 and GPIO_3 of PNEV7462B as follows.

Vdd will be connected to 3V3 pin on the board:

GND can be connected to any GND on the board.
Demonstration:
Each tag was previously written with a text NDEF message respectively.
Tag 1:
Text: Tag1
Language: en
Tag 2:
Text: Tag2
Language: en
Writing to a tag can be done by making use of our TagWriter app available in the play store:
NFC TagWriter by NXP - Aplicaciones de Android en Google Play
- First both tag's NDEF text messages will be displayed:

- Once the information is read, you'll be asked to select an option from the following menu:

- If left button (GPIO_2) is pressed, the content from Tag 1 will be written to Tag 2:

- Otherwise, If left button (GPIO_3) is pressed, the content from Tag 2 will be written to Tag 1:

Please find the modified files attached.
I hope this is of great help!
Best regards,
Ivan.