How to read MIFARE Ultralight TAG with BasicLoopDiscovery Sample

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to read MIFARE Ultralight TAG with BasicLoopDiscovery Sample

跳至解决方案
4,535 次查看
bartekkling
Contributor I

Hello,

How to read MIFARE Ultralight TAG using BasicLoopDiscovery sample. There is even no logs when trying to read this TAG.

When using NTagI2C sample I have read only some info:

Ready to detect

UID:  04 A7 D4 9A E4 21 80

ATQA: 44 00

SAK: 0x0

Type A T2-tag detected

Unable to Read Tag Version information

Execution aborted!!!

I am using CLEV663B board with LPC 1769.

标记 (2)
0 项奖励
回复
1 解答
3,203 次查看
michaelneurohr
NXP Employee
NXP Employee

Since the NTAG-I2C example already detects your tag, let's use this example as the basis.

Can you replace the function "void NfcrdlibEx9_NTagI2C(void *pParams)" from the file NfcrdlibEx9_NTagI2C. completely with the following, please?

void NfcrdlibEx9_NTagI2C(void *pParams)

{

    phStatus_t  status = 0;

    uint16_t    wTagsDetected = 0;

    uint8_t    bTagType;

    uint8_t    *pBuff;

    uint16_t    numOfBytes;

    uint8_t    bSectorNum;

    uint8_t    bMoreCardsAvailable;

    /* Set Interrupt */

    Set_Interrupt();

    /* Initialize library */

    status = NfcRdLibInit();

    CHECK_STATUS(status);

    while(1)    /* Continuous loop */

    {

        DEBUG_PRINTF("\nReady to detect");

        DEBUG_FLUSH('\n');

        do

        {

            /* Field OFF */

            status = phhalHw_FieldOff(pHal);

            CHECK_STATUS(status);

            /* Configure Discovery loop for Poll Mode */

            status = phacDiscLoop_SetConfig(&sDiscLoop, PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE, PHAC_DISCLOOP_POLL_STATE_DETECTION);

            CHECK_STATUS(status);

            /* Run Discovery loop */

            status = phacDiscLoop_Run(&sDiscLoop, PHAC_DISCLOOP_ENTRY_POINT_POLL);

        }while((status & PH_ERR_MASK) != PHAC_DISCLOOP_DEVICE_ACTIVATED); /* Exit on Card detection */

        /* Card detected */

        /* Get the tag types detected info */

        status = phacDiscLoop_GetConfig(&sDiscLoop, PHAC_DISCLOOP_CONFIG_TECH_DETECTED, &wTagsDetected);

        /* Check for Status */

        if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS)

        {

            /* Check for Type A tag detection */

            if (PHAC_DISCLOOP_CHECK_ANDMASK(wTagsDetected, PHAC_DISCLOOP_POS_BIT_MASK_A))

            {

                /* Bit b3 is set to zero, [Digital] 4.8.2 */

                /* Mask out all other bits except for b7 and b6 */

                bTagType = (sDiscLoop.sTypeATargetInfo.aTypeA_I3P3[0].aSak & 0x60);

                bTagType = bTagType >> 5;

                /* Check for Type 2 Tag */

                if (bTagType == PHAC_DISCLOOP_TYPEA_TYPE2_TAG_CONFIG_MASK)

                {

                    /* Read pages 05, 06, 07, 08 */

                    status = phalMful_Read(&salMful, 0x05, bDataBuffer);

                    PRINT_BUFF(&bDataBuffer[0], 16);

                }

            }

        }

    }

}

This should now read out page 05, 06, 07 and 08 and print the content in hex to the console.

Let me know if this helps.

Michael

在原帖中查看解决方案

0 项奖励
回复
8 回复数
3,203 次查看
bartekkling
Contributor I

Hello,

Thanks, that works for me.

I still don't know why BasicDiscoveryLoop was not working, but this is enough to me.

0 项奖励
回复
3,203 次查看
michaelneurohr
NXP Employee
NXP Employee

Great that it works now.

But indeed, that shouldn't be the case, that BasicDiscoveryLoop example isn't working on your side. Do the other examples work for you?

0 项奖励
回复
3,203 次查看
bartekkling
Contributor I

I switched to latest library verson, but this change nothing.

Still basic loop discovery cannot detct my tag, and NTagI2C cant detect tag, but can't read it.

Can u share with me basic application for detecting this type of tag and readng this content?

I am trying to scan this type of tag:

xperia-smarttags-how-to-use-nfc-smarttags.jpg

0 项奖励
回复
3,204 次查看
michaelneurohr
NXP Employee
NXP Employee

Since the NTAG-I2C example already detects your tag, let's use this example as the basis.

Can you replace the function "void NfcrdlibEx9_NTagI2C(void *pParams)" from the file NfcrdlibEx9_NTagI2C. completely with the following, please?

void NfcrdlibEx9_NTagI2C(void *pParams)

{

    phStatus_t  status = 0;

    uint16_t    wTagsDetected = 0;

    uint8_t    bTagType;

    uint8_t    *pBuff;

    uint16_t    numOfBytes;

    uint8_t    bSectorNum;

    uint8_t    bMoreCardsAvailable;

    /* Set Interrupt */

    Set_Interrupt();

    /* Initialize library */

    status = NfcRdLibInit();

    CHECK_STATUS(status);

    while(1)    /* Continuous loop */

    {

        DEBUG_PRINTF("\nReady to detect");

        DEBUG_FLUSH('\n');

        do

        {

            /* Field OFF */

            status = phhalHw_FieldOff(pHal);

            CHECK_STATUS(status);

            /* Configure Discovery loop for Poll Mode */

            status = phacDiscLoop_SetConfig(&sDiscLoop, PHAC_DISCLOOP_CONFIG_NEXT_POLL_STATE, PHAC_DISCLOOP_POLL_STATE_DETECTION);

            CHECK_STATUS(status);

            /* Run Discovery loop */

            status = phacDiscLoop_Run(&sDiscLoop, PHAC_DISCLOOP_ENTRY_POINT_POLL);

        }while((status & PH_ERR_MASK) != PHAC_DISCLOOP_DEVICE_ACTIVATED); /* Exit on Card detection */

        /* Card detected */

        /* Get the tag types detected info */

        status = phacDiscLoop_GetConfig(&sDiscLoop, PHAC_DISCLOOP_CONFIG_TECH_DETECTED, &wTagsDetected);

        /* Check for Status */

        if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS)

        {

            /* Check for Type A tag detection */

            if (PHAC_DISCLOOP_CHECK_ANDMASK(wTagsDetected, PHAC_DISCLOOP_POS_BIT_MASK_A))

            {

                /* Bit b3 is set to zero, [Digital] 4.8.2 */

                /* Mask out all other bits except for b7 and b6 */

                bTagType = (sDiscLoop.sTypeATargetInfo.aTypeA_I3P3[0].aSak & 0x60);

                bTagType = bTagType >> 5;

                /* Check for Type 2 Tag */

                if (bTagType == PHAC_DISCLOOP_TYPEA_TYPE2_TAG_CONFIG_MASK)

                {

                    /* Read pages 05, 06, 07, 08 */

                    status = phalMful_Read(&salMful, 0x05, bDataBuffer);

                    PRINT_BUFF(&bDataBuffer[0], 16);

                }

            }

        }

    }

}

This should now read out page 05, 06, 07 and 08 and print the content in hex to the console.

Let me know if this helps.

Michael

0 项奖励
回复
3,203 次查看
bartekkling
Contributor I

Thanks for reply.

But the problem is, BasicLoopDiscovery even not detect tag. This sample is able to detect some debit cards, but none of my tags.

Thanks for code for reading tag. Once DiscoveryLoop detect my tag I can use it.

I know, that my tag is working, becouse it is detcted by mobiel phone and NTagI2C  sample.

Any ideas, why DiscoveryLoop can't see my tag? I am using NFC Reader Library in version 4.010.00.001602_R1.

0 项奖励
回复
3,203 次查看
michaelneurohr
NXP Employee
NXP Employee

One more thing.

Make sure, there is a 0-Ohm resistor or solder joint on R34. R35 need to be open (no resistor). See AN11211, page 8 chapter 2.5.

0 项奖励
回复
3,203 次查看
michaelneurohr
NXP Employee
NXP Employee

This version should definitely detect these Ultralight tags in example 1. However, you are using an outdated version.

Can you download the latest version 4.010.03.001609, please?

Please download it from

NFC Reader Library|NXP

Michael

0 项奖励
回复
3,203 次查看
michaelneurohr
NXP Employee
NXP Employee

Hi,

when running the BasicDiscoveryLoop example you should get similar print out for Mifrare Ultralight like:

BasicDiscoveryLoop Example:

Card detected and activated successfully...

    Technology  : Type A

        Card: 1

        UID : 04 FD 7D 49 5B 23 80

        SAK : 0x00

        Type: Type 2 Tag

To enhance this example for reading Mifare Ultralight tags, you need to add a few lines of code:

Add the include for the additional Application Layer header:

#include <phalMful.h>

Declare one more AL variable:

phalMful_Sw_DataParams_t salMful;

Add it as a global variable after declaring the PAL variables.

In function NfcRdLibInit() add a initialization for the MFUL AL component. Add the following line after phpalMifare_Sw_Init():

/* Initialize the Mful AL component */

   status = phalMful_Sw_Init(&salMful, sizeof(phalMful_Sw_DataParams_t), &spalMifare, NULL, NULL, NULL);

   CHECK_STATUS(status);

In function BasicDiscoveryLoop_Demo() we will now perform the actual read operation.

First we need to add two more variable. So at the beginning of the function add:

uint8_t bTagType;

uint8_t bDataBuffer[PHAL_MFUL_READ_BLOCK_LENGTH];

Finally we can start with the read operation.

Search for these lines:

/* Get Detected Technology Type */

status = phacDiscLoop_GetConfig(pDataParams, PHAC_DISCLOOP_CONFIG_TECH_DETECTED, &wTagsDetected);

CHECK_STATUS(status);

PrintTagInfo(pDataParams, wNumberOfTags, wTagsDetected);

After these lines add the following code:

/* Check for Type A tag detection */

if (PHAC_DISCLOOP_CHECK_ANDMASK(wTagsDetected, PHAC_DISCLOOP_POS_BIT_MASK_A))

{

    /* Bit b3 is set to zero, [Digital] 4.8.2 */

     /* Mask out all other bits except for b7 and b6 */

     bTagType = (sDiscLoop.sTypeATargetInfo.aTypeA_I3P3[0].aSak & 0x60);

     bTagType = bTagType >> 5;

     /* Check for Type 2 Tag */

     if (bTagType == PHAC_DISCLOOP_TYPEA_TYPE2_TAG_CONFIG_MASK)

     {

         /* Read page 0x05, 0x06, 0x07 and 0x08 */

         status = phalMful_Read(&salMful, 0x05, bDataBuffer);

         PRINT_BUFF(&bDataBuffer[0], 16);

     }

}

The read operation is done in line 13. In this code, page 0x05, 0x06, 0x07 and 0x08 are read. During one read operation always 16 Bytes or 4 pages are read. To start reading from another page you simply need to change the value.

Hope that helps,

Michael

0 项奖励
回复