cancel
Showing results for 
Search instead for 
Did you mean: 

Can anyone provide an example of api rfalST25xVPollerReadMessage?

johnson jiang
Associate II

Hi all:

I want to read mailbox message from nfc tag at nfc reader side.

But i cann't find an example of how to read it, i find an api rfalST25xVPollerReadMessage, but don't know how to use it. Can anyone share it?

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

  1. Open RF user security session with rfalST25xVPollerPresentPassword with pwdNum=0 (RF_PWD_0), pwd=your passwd and pwdLen=8
  2. Authorize the enabling of the MB (set MB_MODE bit to 1 in MB_MODE register thanks to rfalST25xVPollerWriteConfiguration)
  3. Read the current value of the MB_CTRL_Dyn register with rfalST25xVPollerReadDynamicConfiguration
  4. set MB_EN bit to 1 and write the updated value to MB_CTRL_Dyn register with rfalST25xVPollerWriteDynamicConfiguration
  5. read the length of the mailbox message with rfalST25xVPollerReadMessageLength or rfalST25xVPollerFastReadMessageLength (double speed)
  6. read the mailbox message with rfalST25xVPollerReadMessage or rfalST25xVPollerFastReadMessage

#define ST25DV04K_SYSTEM_CONFIG_MB_MODE 0x0D
#define ST25DV04K_REG_MB_MODE_FTM_AUTHORIZED 1U
#define ST25DV04K_DYN_REG_MB_CTRL 0x0D
#define ST25DV04K_REG_MB_CTRL_DYN_MB_EN 1U
 
uint8_t               pointer;
uint8_t               reg;
static uint8_t        pwd[8] = {0,0,0,0,0,0,0,0};
uint8_t               pwdLen = 8;
uint8_t               pwdNum = 0;
uint8_t               msgLen;
ReturnCode            err;
uint16_t              rcvLen;
static uint8_t        rxBuf[256];
 
/* Open RF configuration security session */
err = rfalST25xVPollerPresentPassword(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pwdNum, pwd, pwdLen);
 
/* set MB_MODE to 1: Enabling fast transfer mode is authorized.*/
pointer = ST25DV04K_SYSTEM_CONFIG_MB_MODE;
reg = ST25DV04K_REG_MB_MODE_FTM_AUTHORIZED;
err = rfalST25xVPollerWriteConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pointer, reg);
 
/* set MB_EN to 1: Enable FTM. Read, update and write */
pointer = ST25DV04K_DYN_REG_MB_CTRL;
err = rfalST25xVPollerFastReadDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pointer, &reg);
reg |= ST25DV04K_REG_MB_CTRL_DYN_MB_EN;
err = rfalST25xVPollerFastWriteDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pointer, reg);
 
/* Read Msg Len */
err = rfalST25xVPollerFastReadMessageLength(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, &msgLen);
 
/* Read Msg */
err = rfalST25xVPollerReadMessage(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, 0,0, rxBuf, sizeof(rxBuf), &rcvLen);

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

6 REPLIES 6
Ulysses HERNIOSUS
ST Employee

Hi,

please check 5.1.2 of the DS of e.g. ST25DV64K. The last paragraph details an example usage. The functions more or less directly translate into rfal calls to:

rfalST25xVPollerWriteDynamicConfiguration(), rfalST25xVPollerReadMessage(), rfalST25xVPollerWriteMessage(), rfalST25xVPollerReadDynamicConfiguration().

Before reading / writing the mailbox please make sure to have the ST25DV in the right state: Maybe present the PW, maybe disable EH to avoid RF noise, initialize mailbox by setting MB_EN 0->1.

Regards, Ulysses

Brian TIDAL
ST Employee

Hi,

  1. Open RF user security session with rfalST25xVPollerPresentPassword with pwdNum=0 (RF_PWD_0), pwd=your passwd and pwdLen=8
  2. Authorize the enabling of the MB (set MB_MODE bit to 1 in MB_MODE register thanks to rfalST25xVPollerWriteConfiguration)
  3. Read the current value of the MB_CTRL_Dyn register with rfalST25xVPollerReadDynamicConfiguration
  4. set MB_EN bit to 1 and write the updated value to MB_CTRL_Dyn register with rfalST25xVPollerWriteDynamicConfiguration
  5. read the length of the mailbox message with rfalST25xVPollerReadMessageLength or rfalST25xVPollerFastReadMessageLength (double speed)
  6. read the mailbox message with rfalST25xVPollerReadMessage or rfalST25xVPollerFastReadMessage

#define ST25DV04K_SYSTEM_CONFIG_MB_MODE 0x0D
#define ST25DV04K_REG_MB_MODE_FTM_AUTHORIZED 1U
#define ST25DV04K_DYN_REG_MB_CTRL 0x0D
#define ST25DV04K_REG_MB_CTRL_DYN_MB_EN 1U
 
uint8_t               pointer;
uint8_t               reg;
static uint8_t        pwd[8] = {0,0,0,0,0,0,0,0};
uint8_t               pwdLen = 8;
uint8_t               pwdNum = 0;
uint8_t               msgLen;
ReturnCode            err;
uint16_t              rcvLen;
static uint8_t        rxBuf[256];
 
/* Open RF configuration security session */
err = rfalST25xVPollerPresentPassword(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pwdNum, pwd, pwdLen);
 
/* set MB_MODE to 1: Enabling fast transfer mode is authorized.*/
pointer = ST25DV04K_SYSTEM_CONFIG_MB_MODE;
reg = ST25DV04K_REG_MB_MODE_FTM_AUTHORIZED;
err = rfalST25xVPollerWriteConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pointer, reg);
 
/* set MB_EN to 1: Enable FTM. Read, update and write */
pointer = ST25DV04K_DYN_REG_MB_CTRL;
err = rfalST25xVPollerFastReadDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pointer, &reg);
reg |= ST25DV04K_REG_MB_CTRL_DYN_MB_EN;
err = rfalST25xVPollerFastWriteDynamicConfiguration(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, pointer, reg);
 
/* Read Msg Len */
err = rfalST25xVPollerFastReadMessageLength(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, &msgLen);
 
/* Read Msg */
err = rfalST25xVPollerReadMessage(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, 0,0, rxBuf, sizeof(rxBuf), &rcvLen);

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Brian:

Thanks!

It helps. I want to ask some detail. Where does parameter uid of these functions come from?

I guess function rfalNfcvPollerCheckPresence, and it returns a structure of rfalNfcvInventoryRes which has a field of UID.right?

And i follows exampleRfalPoller.c in RFAL librariy which ST SW provides. In the state EXAMPLE_RFAL_POLLER_STATE_DATAEXCHANGE_START, i invoke

rfalST25xVPollerReadMessage to get message from the tag. Is that work?

Best Regards,

Johnson

Hi:

Your info is at tag side. But i am interested in the reader side.

But your reply is stall valuable.

you metion " disable EH to avoid RF noise" , do you mean when i operate nfc tag, i should disable EH mode each i want to read mailbox message sent by reader.

Brian TIDAL
ST Employee

Hi

Internally the RFAL is divided into three sub layers:

  • RF HL - RF Higher Layer with RFAL NFC API
  • RF AL - RF Abstraction Layer 
  • RF HAL - RF Hardware Abstraction Layer

The  exampleRfalPoller.c aims to demonstrate RF AL sub layer API. I would recommend to rather use the RF High Layer API and to use the demo.c provided within the poller demo in X-CUBE-NFC3 (ST25R95 reader), X-CUBE-NFC5 (ST25R3911B reader) or X-CUBE-NFC6 (ST25R3916 reader).

In this demo.c file, a default demoNfcv() function is provided. You can simply modify this demoNfcv() function to add you code. This function has a nfcvDev parameter and the uid is nfcvDev->InvRes.UID.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi,

well I regard my answer as being from the reader side - the reader does drive the RF communication and I hinted on the to be used reader/rfal functions. But Brian below already went into the details of usage.

Regarding Energy Harvesting disable: If you are anyhow powered at the time of communication it is probably safer to disable it during that time. Any change of power drawn will affect the reader field and could be see by the receiver inside the reader. I think it is not strictly necessary and maybe you are not able to observe an effect. But depending on your actual design it may have an effect.

There is an appnote discussing such effects: AN4913 "Energy harvesting delivery impact on ST25DVxxx behavior during RF communication"

Regards, Ulrich