2023-12-27 04:17 PM - edited 2023-12-27 04:27 PM
Project : STM32L476RG-Nucleo\Applications\X-NUCLEO-NFC04A1\FTM
For read, you always add one to the result of the length read:
*msg_len = mblength + 1;
Seems reasonable when mblengh is 255 , and you add one to read 256 bytes , which is the max mailbox size.
But not after Init. As I clear the mailbox, and read it, mblength is 0, as expected. But I still read 1 byte ( = 0xFF)
What is this byte? kinda confusing!
Using you package code:
ST25FTM_MessageStatus_t ST25FTM_ReadMessage(uint8_t *msg, uint32_t* msg_len)
{
int ret = NFCTAG_OK;
uint16_t mblength = 0;
/* Read length of message */
ret = NFC04A1_NFCTAG_ReadMBLength_Dyn(0, (uint8_t *)&mblength );
if( ret != NFCTAG_OK )
{
return ST25FTM_MSG_ERROR;
}
*msg_len = mblength + 1;
/* Read all data in Mailbox */
ret = NFC04A1_NFCTAG_ReadMailboxData( 0, msg, 0, *msg_len );
if(ret == NFCTAG_OK)
{
mailboxStatus = ST25FTM_MESSAGE_EMPTY;
/* Trick to automatically detect the max frame length of the reader
To have this auto detection working, the reader must send a long command
before receiveing a long response.
*/
ST25FTM_Ctrl_Byte_t ctrl;
ctrl.byte = msg[0];
if((!ST25FTM_CTRL_HAS_PKT_LEN(ctrl)) && !(msg[0] & ST25FTM_STATUS_BYTE))
{
ST25FTM_SetRxFrameMaxLength(*msg_len);
ST25FTM_SetTxFrameMaxLength(*msg_len);
}
return ST25FTM_MSG_OK;
}
return ST25FTM_MSG_ERROR;
}
Solved! Go to Solution.
2024-01-22 12:52 AM
Hi DS.4,
The 0xFF value is the cleared value of the FTM memory.
As the memory is cleared mblength is 0, so you read 1 byte (0 + 1) the first byte of this memory. The tag returns the cleared value which is 0xFF (similarly if you read all the mailbox you will received 256 0xFF).
This is the case when the tag is rebooted or Mailbox is enabled (if previous state was disabled).
Kind Regards.
2024-01-22 12:52 AM
Hi DS.4,
The 0xFF value is the cleared value of the FTM memory.
As the memory is cleared mblength is 0, so you read 1 byte (0 + 1) the first byte of this memory. The tag returns the cleared value which is 0xFF (similarly if you read all the mailbox you will received 256 0xFF).
This is the case when the tag is rebooted or Mailbox is enabled (if previous state was disabled).
Kind Regards.