Activating multiple Tags using NFC Reader Library

原文地址::https://community.nxp.com/docs/DOC-335265


Hello NFC enthusiasts,

 

In the NFC communication protocol, when a device acts as a NFC reader (it provides its own field), it is waiting for a tag to approach. When this occurs, the reader energizes the tag and depending on the application, it can read from or write to a tag.

 

When multiple tags are in the field, the power decreases according to the number of tags being energized, for which the tag operations will not work properly. For this, there is a process called anti-collision, in which the reader decides, from the detected tags, one to work with.

 

The purpose of this document is to demonstrate the activation of each tag at a given index.

 

This demonstration is going to be made with two NTAG 216.

 

 

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))

     

 

Until now, the reader is able to detect a maximum of two tags and work with up to two type A devices.

 

The activation of a tag at a given index is possible to the phacDiscLoop_ActivateCard() function.

 

Once this function is called, it will receive the discovery loop data parameters, the type of tag and the index of a tag to be activated.

 

  • The code will be added after knowing that multiple tags are detected and resolved in the NfcrdlibEx3_NFCForum.c file.

 

else if((status & PH_ERR_MASK) == PHAC_DISCLOOP_MULTI_DEVICES_RESOLVED)
 {
 /*
 * Multiple cards resolved. It enters here if DEVICE LIMIT > 1 and more than one devices are
 * detected and resolved.
 */
 DEBUG_PRINTF (" \n Multiple cards resolved: \n");
/* Get detected technology type */
 status = phacDiscLoop_GetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_TECH_DETECTED, &wTagsDetected);
 CHECK_STATUS(status);
/* Get number of tags detected */
 status = phacDiscLoop_GetConfig(pDiscLoop, PHAC_DISCLOOP_CONFIG_NR_TAGS_FOUND, &wNumberOfTags);
 CHECK_STATUS(status);
DEBUG_PRINTF ("\tNumber of tags: %d \n",wNumberOfTags);

/* Code */

...

}

Note: The code to be inserted in the comment /* Code */ is below in the Code section of this document.

 

The demonstration will be as simple as activating one tag, read its NDEF message, activate the second tag and read its NDEF message as well so that we make sure the activation process is performed correctly.

 

Each tag was previously written with a text NDEF message respectively.

 

Tag 1:

Text: Hallo!

Language: de

 

Tag 2:

Text: ¡Hola!

Language: es

 

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 

 

Code section:

 

uint8_t bTagState1;

/* Tag 1 */

/* Activate tag at index 0 */
status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x00);

/* Check for NDEF presence */
 status = phalTop_CheckNdef(palTop, &bTagState1);

/* Read NDEF message */
status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
 DEBUG_ERROR_PRINT(status);

/* Tag 2 */

/* Activate tag at index 1 */
status = phacDiscLoop_ActivateCard(pDataParams, PHAC_DISCLOOP_TECH_TYPE_A, 0x01);

/* Check for NDEF presence */
 status = phalTop_CheckNdef(palTop, &bTagState1);

/* Read NDEF message */
status = ReadNdefMessage(PHAL_TOP_TAG_TYPE_T2T_TAG);
 DEBUG_ERROR_PRINT(status);

 

Behavior shown in the console monitor:

 

NFC Forum Example:

 

 

 

This implementation demonstrated the activation of two type A tags at a given index.

I hope this is of great help!

 

Best regards,

Ivan.

1 位用户发现它有用

附件




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值