Skip to main content
Visitor II
May 17, 2018
Solved

ST25R3911B calls to read/write block (after successful inventory/get ID)

  • May 17, 2018
  • 3 replies
  • 2264 views
Posted on May 18, 2018 at 01:14

As

previously reported on another post I can

do an 

'inventory' and get a tag ID back successfully.  I did that by getting

 the example 

application

 for 

STM32F401RE-Nucleo

 and X-NUCLEO

-NFC0A1 boards ==>>  code is STM32CubeExpansion_NFC5_V1.2.0

I am now trying to read and write to the tag.  Unfortunately the above example code stops at getting an 'inventory'.

After getting the inventory here:

 

 

rfalNfcvPollerInitialize();           /* Initialize for NFC-F */

  rfalFieldOnAndStartGT();              /* Turns the Field On if not already and start GT timer */

 

  err = rfalNfcvPollerCollisionResolution(1, &nfcvDev, &devCnt);

  if( (err == ERR_NONE) && (devCnt > 0) )

  {

    /******************************************************/

    /* NFC-V card found                                   */

    /* NFCID/UID is contained in: invRes.UID */

    REVERSE_BYTES(nfcvDev.InvRes.UID, RFAL_NFCV_UID_LEN);

    

    found = true;

  }

I am continuing with this:

   

uint8_t rxBuf[1] = {0x55}, wrData = 0xAA;

    uint16_t rcvLen = 1;

    uint8_t flags = RFAL_NFCV_REQ_FLAG_DEFAULT;

    

    err = rfalNfvReadSingleBlock( flags, nfcvDev.InvRes.UID, 1, rxBuf, 1, &rcvLen );

 

    err = rfalNfvWriteSingleBlock( flags, nfcvDev.InvRes.UID, 1, &wrData, 1 );

 

    err = rfalNfvReadSingleBlock( flags, nfcvDev.InvRes.UID, 1, rxBuf, 1, &rcvLen );

 

    if (rxBuf[1] == wrData)

    {

        sys_delay_ms(100);

    }

    else

    {

        sys_delay_ms(200);

    }

But the calls to read/write always return a timeout error.

Is it OK to just continue after getting the ID from a tag?  

Should I have to turn the antenna off, then back on first?

Are there additional steps after rfalNfcvPollerCollisionResolution()

 

and before rfalNfvReadSingleBlock()

?

Maybe the flags value has to be more than just the default?

Etc...

Is there an example SW that actually does read/write operations and does not stop at getting inventory?

Thanks and regards,

Gil

#st25r3911b #iso15693
    This topic has been closed for replies.
    Best answer by Grégoire Poulain
    Posted on May 24, 2018 at 13:20

    Hi Guilherme,

    Indeed, thelast versionreleasedhas a mismatch between declaration (on rfal_nfcv.h) and the implementation(on rfal_nfcv.c).

    This will be fixed in the next release. Please align these to make use of the APIs.

    Also, as mentioned previously there's an issue on these commands for using theAdressed mode.

    Therefore, until a new version gets released please make use of the Select Mode as bellow (in the previous comment the Select cmd was not copied in - edited)

    #define NFCV_BLOCK_LEN 4
    ...
    found = true;
    ...
    {
     uint8_t rxBuf[1 + NFCV_BLOCK_LEN + 2], wrData[NFCV_BLOCK_LEN] = { 0x11, 0x22, 0x33, 0x44 };
     uint16_t rcvLen = 1;
     
    #if 0 /* Addressed mode */
     
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     err = rfalNfcvPollerWriteSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID, 1, wrData, sizeof(wrData));
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     
    #else /* Select mode */
     
     err = rfalNfvPollerSelect(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID);
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     err = rfalNfcvPollerWriteSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, wrData, sizeof(wrData));
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     
    #endif
    }
     REVERSE_BYTES(nfcvDev.InvRes.UID, RFAL_NFCV_UID_LEN);
    ...�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    Kind regards

    GP

    3 replies

    ST Employee
    May 23, 2018
    Posted on May 23, 2018 at 15:05

    Dear Guilherme,

    As sent via email, the code bellow has the following issues:

    1. It is mentioned that the driver used is from

      STM32CubeExpansion_NFC5_V1.2.0

      but from the APIs it seems thatyou are using an older version.

    The new APIs are:

    rfalNfcvPollerReadSingleBlock

    rfalNfcvPollerWriteSingleBlock

    There’s an issue on these commands when communicating with the tag in the addressed mode (with UID).

    A new release is still being prepared, so currently there’s no published release available with the fix, but we can share thediff/patch if needed.

    1. If the addressed mode is required, then the UID cannot be reverted.

    That is currently performed for human readability only, but to make use of the UID on the following commands it must not be reversed.

    //REVERSE_BYTES(nfcvDev.InvRes.UID, RFAL_NFCV_UID_LEN);

    If the addressed mode is not required, just use NULL for the UID parameter.

    1. The rxBuf is too small (1 byte).

    ISO15693 tags usually have blocks of 4 bytes each, but can be as big as 32 bytes.

    Please increase the rxBuf accordingly, and also pass a full block when writing the block as well.

    The following code should work for you:

    #define NFCV_BLOCK_LEN 4
     ...
    /******************************************************/
    /* NFC-V card found */
    /* NFCID/UID is contained in: invRes.UID */
    
    found = true;
     
    {
     uint8_t rxBuf[1 + NFCV_BLOCK_LEN + 2], wrData[NFCV_BLOCK_LEN] = { 0x11, 0x22, 0x33, 0x44 };
     uint16_t rcvLen = 1;
     
     err = rfalNfvPollerSelect(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID);
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, rxBuf, sizeof(rxBuf), &rcvLen); 
     err = rfalNfcvPollerWriteSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, wrData, sizeof(wrData));
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, rxBuf, sizeof(rxBuf), &rcvLen);
    }
    REVERSE_BYTES(nfcvDev.InvRes.UID, RFAL_NFCV_UID_LEN);�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    Kind regards

    GP

    EDIT: code snippet edited

    Updated

    Visitor II
    May 23, 2018
    Posted on May 23, 2018 at 18:04

     ,

     ,

    Hi Gr

    é

    goire,

    Thank you for the information. , I tried it but I still get a timeout error.

    I suspected that the problem was on our HW ,side (antenna power, etc), so I also added that code to the ,

    STM32CubeExpansion_NFC5_V1.2.0 ,

    code and used the ST development boards (NUCLEO-F401RE and X-NUCLEO-NFC05A1) to test. , It also returns a timeout error. , So maybe there is more to it.

     ,

    I also noticed one thing:

     ,

    rfal_nfcv.h names the functions '

    rfalNfv

    Poller

    ReadSingleBlock', etc

     ,

    ... but ...

     ,

    rfal_nfcv.c names them '

    rfalNfv

    ReadSingleBlock', etc (without the ,

    Poller

     ,

    in the name)

     ,

    To be able to call them I needed to rename them in the .h file, but I'm afraid that for some reason rfal_nfcv.c is an older version of the file, inadvertently included in the new SDK.

     ,

    Could you check this on your side?

     ,

    Here's how my code looks like now:

     ,

    ♯ define NFCV_BLOCK_LEN ,  ,4

     ,  , ,

    uint8_t rxBuf[1 + NFCV_BLOCK_LEN + 2], wrData[NFCV_BLOCK_LEN] = { 0x11, 0x22, 0x33, 0x44 },

    uint16_t rcvLen = 1, // or ,sizeof(rxBuf)

    uint8_t flags = RFAL_NFCV_REQ_FLAG_DEFAULT,

     ,  , ,

     ,  , err = rfalNfvPollerReadSingleBlock( flags, NULL, 1, rxBuf, sizeof(rxBuf), &,rcvLen ),

     ,

     ,  , err = rfalNfvPollerWriteSingleBlock( flags, NULL, 1, wrData, sizeof(wrData) ),

     ,

     ,  , err = rfalNfvPollerReadSingleBlock( flags, NULL, 1, rxBuf, sizeof(rxBuf), &,rcvLen ),

     ,

     ,  , if (rxBuf[1] == wrData[0]) ,

    // Just a place to set a breakpoint

     ,  , {

     ,  ,  ,  , wrData[2]++, // Just a place to set a breakpoint

     ,  , }

     ,  , else

     ,  , {

     ,  ,  ,  , wrData[3]++, // Just a place to set a breakpoint

     ,  , }

     ,

    Thanks and regards,

    Gil

    ST Employee
    May 24, 2018
    Posted on May 24, 2018 at 13:20

    Hi Guilherme,

    Indeed, thelast versionreleasedhas a mismatch between declaration (on rfal_nfcv.h) and the implementation(on rfal_nfcv.c).

    This will be fixed in the next release. Please align these to make use of the APIs.

    Also, as mentioned previously there's an issue on these commands for using theAdressed mode.

    Therefore, until a new version gets released please make use of the Select Mode as bellow (in the previous comment the Select cmd was not copied in - edited)

    #define NFCV_BLOCK_LEN 4
    ...
    found = true;
    ...
    {
     uint8_t rxBuf[1 + NFCV_BLOCK_LEN + 2], wrData[NFCV_BLOCK_LEN] = { 0x11, 0x22, 0x33, 0x44 };
     uint16_t rcvLen = 1;
     
    #if 0 /* Addressed mode */
     
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     err = rfalNfcvPollerWriteSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID, 1, wrData, sizeof(wrData));
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     
    #else /* Select mode */
     
     err = rfalNfvPollerSelect(RFAL_NFCV_REQ_FLAG_DEFAULT, nfcvDev.InvRes.UID);
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     err = rfalNfcvPollerWriteSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, wrData, sizeof(wrData));
     err = rfalNfcvPollerReadSingleBlock(RFAL_NFCV_REQ_FLAG_DEFAULT, NULL, 1, rxBuf, sizeof(rxBuf), &rcvLen);
     
    #endif
    }
     REVERSE_BYTES(nfcvDev.InvRes.UID, RFAL_NFCV_UID_LEN);
    ...�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

    Kind regards

    GP

    Graduate
    August 16, 2018

    Hi,

    I am also working on an RFID reader system using STM32l031, I imported the rfal library from the NFC demo board with Nucleo and managed to detect the tag and now I need to develop the read and write functions.

    So far, thanks to your post I can read the block 0 of my ISO15693 tag.

    however, I fail to read any other blocks using the rfalNfvPollerReadSingleBlock function and setting the parameter blockNum to the desired block address.

    I tried to use the help file but I can't open any article.

    I laso can't find documentation about the flags (only using RFAL_NFCV_REQ_FLAG_DEFAULT which value is equal to RFAL_NFCV_REQ_FLAG_DATA_RATE).

    kind regards,

    Yves

    Graduate
    August 16, 2018

    ok found the problem, need to comment / remove the line as shown:

      /* Check if request is to be sent in Addressed or Selected mode */

      if( uid != NULL )

      {

        req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_ADDRESS;

        ST_MEMCPY( req.payload.UID, uid, RFAL_NFCV_UID_LEN );

        msgIt += RFAL_NFCV_UID_LEN;

        req.payload.data[ (/*RFAL_NFCV_UID_LEN + */msgIt++) ] = blockNum; // comment or remove RFAL_NFCV_UID_LEN

      }

      else

      {

        req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_SELECT;

        req.payload.data[msgIt++] = blockNum;

      }

    regards,

    Yves