cancel
Showing results for 
Search instead for 
Did you mean: 

X-NUCLEO_NFC04A1 mailbox

sebastianst
Associate

Hi,

I am working with the X-NUCLEO-NFC04A1 board and would like to use its mailbox functionality. So far, I have been using the example provided by ST, where the mailbox is used to write and read data using the same device.

I have extended this example and successfully managed to read the mailbox content sent using the NFC Tools application. Now, I would like to take it a step further and write data to the mailbox of other NFC devices using my NFC04A1.

Could someone explain to me how I can do this? How can I configure my program to write data directly to the mailbox of another NFC device using the NFC04A1?

Thank you in advance for your help!

Here is the main function of the program:

 

void MX_NFC4_MAILBOX_Init(void)
{
 /* Init of the Leds on X-NUCLEO-NFC04A1 board */
  NFC04A1_LED_Init(GREEN_LED);
  NFC04A1_LED_Init(BLUE_LED);
  NFC04A1_LED_Init(YELLOW_LED);

  NFC04A1_LED_On( GREEN_LED );
  HAL_Delay( 300 );
  NFC04A1_LED_On( BLUE_LED );
  HAL_Delay( 300 );
  NFC04A1_LED_On( YELLOW_LED );
  HAL_Delay( 300 );

   /* Init UART for display message on console */
  BSP_COM_Init(COM1);

  printf( "----------------------------------------" );
  printf( "\n\r*****Welcome to x-cube-nfc4 example*****" );
  printf( "\n\r----------------------------------------" );

  /* Init ST25DV driver */
  while(NFC04A1_NFCTAG_Init(NFC04A1_NFCTAG_INSTANCE) != HAL_OK);

  /* Init done */
  NFC04A1_LED_Off( GREEN_LED );
  HAL_Delay( 300 );
  NFC04A1_LED_Off( BLUE_LED );
  HAL_Delay( 300 );
  NFC04A1_LED_Off( YELLOW_LED );
  HAL_Delay( 300 );

  printf( "\n\r\n\r This program will show you basic example on how to use the mailbox on I2C side" );
  /* If not activated, activate Mailbox, as long as MB is ON EEPROM is not available */
  NFC04A1_NFCTAG_ReadMBMode(NFC04A1_NFCTAG_INSTANCE, &MB_mode);
  if( MB_mode == ST25DV_DISABLE )
  {
    /* You need to present password before changing static configuration */
    NFC04A1_NFCTAG_ReadI2CSecuritySession_Dyn(NFC04A1_NFCTAG_INSTANCE, &i2csso );
    if( i2csso == ST25DV_SESSION_CLOSED )
    {
      /* if I2C session is closed, present password to open session */
      passwd.MsbPasswd = 0; /* Default value for password */
      passwd.LsbPasswd = 0; /* change it if password has been modified */
      NFC04A1_NFCTAG_PresentI2CPassword(NFC04A1_NFCTAG_INSTANCE, passwd );
    }
   NFC04A1_NFCTAG_WriteMBMode(NFC04A1_NFCTAG_INSTANCE,ST25DV_ENABLE);

    /* Close session as dynamic register doesn't need open session for modification */
    passwd.MsbPasswd = 123;
    passwd.LsbPasswd = 123;
	NFC04A1_NFCTAG_PresentI2CPassword(NFC04A1_NFCTAG_INSTANCE, passwd );
  }

  /* Enable Mailbox in dynamique register */
  NFC04A1_NFCTAG_SetMBEN_Dyn(NFC04A1_NFCTAG_INSTANCE);

  printf( "\n\r\n\rMailbox is activated" );

  /* prepare data to write */
  for( cnt = 0; cnt < 16; cnt++ )
  {
    awritedata[cnt] = cnt;
  }

  /* Check if Mailbox is available */
NFC04A1_NFCTAG_ReadMBCtrl_Dyn( NFC04A1_NFCTAG_INSTANCE,&mbctrldynstatus );

  /* If MB is available, write data */
if( (mbctrldynstatus.HostPutMsg == 0) && (mbctrldynstatus.RfPutMsg == 0) )
{
    printf( "\n\r\n\rMailbox available, write data to it" );
    NFC04A1_NFCTAG_WriteMailboxData( NFC04A1_NFCTAG_INSTANCE, awritedata, 5 );
}

  /* Read length of message */
  NFC04A1_NFCTAG_ReadMBLength_Dyn(NFC04A1_NFCTAG_INSTANCE, (uint8_t *)&mblength );
  printf( "\n\r\n\rLength of data write in MBCTRL register : %d", mblength );
  mblength++;
  printf( "\n\rNeed to add 1 to the length as it start at 0 : %d", mblength );
  /* Read mailbox status */
  NFC04A1_NFCTAG_ReadMBCtrl_Dyn( NFC04A1_NFCTAG_INSTANCE,&mbctrldynstatus );
  printf( "\n\r\n\rCtrl MB status register value:" );
  printf( "\n\rHost(i2c) Missed Message  = %d", mbctrldynstatus.HostMissMsg );
  printf( "\n\rRF(reader) Missed Message = %d", mbctrldynstatus.RFMissMsg );
  printf( "\n\rHost(i2c) Put Message     = %d", mbctrldynstatus.HostPutMsg );
  printf( "\n\rRF(reader) Put Message    = %d", mbctrldynstatus.RfPutMsg );
  printf( "\n\rMailbox Enable            = %d", mbctrldynstatus.MbEnable );

  /* Read all data in Mailbox */
  NFC04A1_NFCTAG_ReadMailboxData( NFC04A1_NFCTAG_INSTANCE,areaddata, 0, mblength );
  printf( "\n\r\n\rData read in Mailbox:\n\r" );
  /* prepare data to write */
  for( cnt = 0; cnt < 5; cnt++ )
  {
    printf( "0x%02X ", areaddata[cnt] );
  }

  NFC04A1_NFCTAG_ResetMBEN_Dyn(NFC04A1_NFCTAG_INSTANCE);
  NFC04A1_NFCTAG_SetMBEN_Dyn(NFC04A1_NFCTAG_INSTANCE);

  /* Read all data in Mailbox */
  NFC04A1_NFCTAG_ReadMailboxData(NFC04A1_NFCTAG_INSTANCE, areaddata, 0, mblength );
  printf( "\n\r\n\rClear mailbox by de/reactivate it or by reading it with a reader, read data:\n\r" );
  /* prepare data to write */
  for( cnt = 0; cnt < 5; cnt++ )
  {
    printf( "0x%02X ", areaddata[cnt] );
  }

  printf( "\n\r\n\r----------------------------------------" );
  printf( "\n\r*****        end of example        *****" );
  printf( "\n\r----------------------------------------\n\r\n\r" );

}

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rene Lenerve
ST Employee

Hi sebastianst,

The NFC04 is a nucleo expansion board embedding an ST tag (ST25DV), so this component is therefore passive with respect to NFC. That means tags cannot read or write other NFC components, they are only memories that can be accessed by a reader (or smartphones with nfc).

Dynamic tags (like ST25DV) offers also an i²c interface to connect to MCUs, that allows a micro-controller to access this memory too (in addition to the NFC reader), therefor exchanges can be done between RF Reader and MCU using the tag's memory but only the Reader can engage exchanges. As for writing to EEPROM can take some time, one feature of the ST25DV is the mailbox that give access to a RAM area for both Reader and MCU.
If you want to communicate between the Reader and the MCU via this mailbox. You need to write to the mailbox with the MCU and then read it with a reader.and reciprocally write data with a reader which will be readable by the MCU.

Kind Regards.

 
 

 

 

View solution in original post

1 REPLY 1
Rene Lenerve
ST Employee

Hi sebastianst,

The NFC04 is a nucleo expansion board embedding an ST tag (ST25DV), so this component is therefore passive with respect to NFC. That means tags cannot read or write other NFC components, they are only memories that can be accessed by a reader (or smartphones with nfc).

Dynamic tags (like ST25DV) offers also an i²c interface to connect to MCUs, that allows a micro-controller to access this memory too (in addition to the NFC reader), therefor exchanges can be done between RF Reader and MCU using the tag's memory but only the Reader can engage exchanges. As for writing to EEPROM can take some time, one feature of the ST25DV is the mailbox that give access to a RAM area for both Reader and MCU.
If you want to communicate between the Reader and the MCU via this mailbox. You need to write to the mailbox with the MCU and then read it with a reader.and reciprocally write data with a reader which will be readable by the MCU.

Kind Regards.