cancel
Showing results for 
Search instead for 
Did you mean: 

rfalST25xVPollerFastWriteMessage() fails writing to mailbox

liuxinguo
Associate

hi,

    I have some code for reading/writing to a mailbox from the ST25R3916B transceiver to a ST25DV64KC tag. The read passes but the write fails every time;its errcode is ERR_PROTO;

My code is following:

static void demo2Nfcv(rfalNfcvListenDevice *nfcvDev)
{
    ReturnCode err;
    uint16_t rcvLen;
    uint8_t blockNum = 0;
    //uint8_t rxBuf[1 + DEMO_NFCV_BLOCK_LEN + RFAL_CRC_LEN]; /* Flags + Block Data + CRC */
    uint8_t *uid;
    uint8_t cir = 0; //循环次数
    uint8_t wrData[DEMO_NFCV_BLOCK_LEN] = {0};         /* Write block example */
                                                       /* DEMO_NFCV_WRITE_TAG */
	uint8_t tempTxBuf[256] = {0};
	uint8_t i=0;
	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;
	uint8_t msgBuf[4] = {0x01,0x02,0x03,0x04};
	static uint8_t        rxBuf[256];

    uid = nfcvDev->InvRes.UID;
	/* 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);
	
	err = rfalST25xVPollerFastWriteMessage(RFAL_NFCV_REQ_FLAG_DEFAULT, uid,3,msgBuf,tempTxBuf,256);
	
	 
	/* Read Msg Len */
	err = rfalST25xVPollerFastReadMsgLength(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, &msgLen);
	 
	/* Read Msg */
	err = rfalST25xVPollerReadMessage(RFAL_NFCV_REQ_FLAG_DEFAULT, uid, 0,0, rxBuf, sizeof(rxBuf), &rcvLen);
}

Can anyone help me solve that probl

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

See Datasheet §7.6.31 Write Message:

"The command can be executed only when the mailbox is accessible by RF (fast transfer mode is enabled, previous RF message was read or time-out occurs, no I2C message to be read). User can check it by reading b1 of MB_CTRL_Dyn “HOST_PUT_MSG” which must be reset to 0. "

Make sure the content of the Mailbox is read before the next Write Message. 

An example of usage of the FTM is available in the ST25 NFC Embedded Library (FTM demo). 

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

8 REPLIES 8
Ulysses HERNIOSUS
ST Employee

Hi,

most likely reason is the tag having returned with error flag set. Please inspect the function - res.RES_FLAG should contain the tag's error code.

Regards, Ulysses

Brian TIDAL
ST Employee

Hi,

I've tried your code on my side and did not faced any issue.

Make sure that the following defines are correct (see ST25DV64KC Datasheet):

  • ST25DV04K_SYSTEM_CONFIG_MB_MODE 0x0D
  • ST25DV04K_REG_MB_MODE_FTM_AUTHORIZED 0x01
  • ST25DV04K_DYN_REG_MB_CTRL 0x0D
  • ST25DV04K_REG_MB_CTRL_DYN_MB_EN 0x01

Make sure that the Vcc is present (see datasheet Table 18 for the Write access)

Also make sure to test the return code of the various calls to rfalST25xVPoller API.

If an error is still faced, set a breakpoint in rfalST25xVPollerFastWriteMessage and walk through until rfalTransceiveBlockingTxRx is reached and then check the 2 possible cases where a RFAL_ERR_PROTO is returned.

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,

     Thanks you for your reply. First,I check what you said about some macro definition,it is correct. 

 secondly,the vcc is present;Finally,the return code of rfalTransceiveBlockingTxRx API is 0;res.RES_FLAG is 0x01,so last retutn code is 0x0B

    /* Transceive Command */
    ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX );
    
    
    /* Restore Rx BitRate */
    if( fastMode )
    {
        rfalSetBitRate( RFAL_BR_KEEP, rxBR );
    }
    
    if( ret != ERR_NONE )
    {
        return ret;
    }
    
    /* Check if the response minimum length has been received */
    if( rcvLen < (uint8_t)RFAL_NFCV_FLAG_LEN )
    {
        return ERR_PROTO;
    }
    
    /* Check if an error has been signalled */
    if( (res.RES_FLAG & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U )
    {
        return ERR_PROTO;
    }

 

res.RES_FLAG is 0x01 ; it means RFAL_NFCV_RES_FLAG_ERROR;

Hi,

    today,I write data to FTM mail successsfully.the problem that I meet before  is producted when I make ST25DV it that it write datas to ftm mail . 

   But now,I only write successfully at a time.If I write datas again,the ret code is still 0x0B

Hi,

-edited-

my mistake: I wanted to ask for the returned error code. It is not in res.RES_FLAG but in res.data[0].

Please inspect that one and compare against DS 7.4.8 Response and error code:

BR, Ulysses

Hi,

See Datasheet §7.6.31 Write Message:

"The command can be executed only when the mailbox is accessible by RF (fast transfer mode is enabled, previous RF message was read or time-out occurs, no I2C message to be read). User can check it by reading b1 of MB_CTRL_Dyn “HOST_PUT_MSG” which must be reset to 0. "

Make sure the content of the Mailbox is read before the next Write Message. 

An example of usage of the FTM is available in the ST25 NFC Embedded Library (FTM demo). 

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.

thanks for your help.the problem is solved.