cancel
Showing results for 
Search instead for 
Did you mean: 

how to use X-NUCLEO-NFC04A1 tag ? Please share its base code .

Pooja Sain
Associate II

Hello,

I already used x-cube-nfc4 as a basic code for application use of RFID tag but it didn't work only it indicates the nfc tap while using near to tag and even this code doesn't support uart. So, i want to know why UART is not supporting in it. I am attaching the code which I used.

#include "main.h"

UART_HandleTypeDef huart;

sURI_Info URI;

extern sCCFileInfo CCFileStruct;

/* Private function prototypes -----------------------------------------------*/

void UARTConsoleConfig( void );

HAL_StatusTypeDef UARTConsolePrint( char *puartmsg );

extern void SystemClock_Config( void );

int main( void )

{

 char uartmsg[6]="hello";

 HAL_Init( );

 /* Configure the System clock */

 SystemClock_Config( );

  

  /* Init of the Nucleo Board led */

// BSP_LED_Init(LED2);

 /* Init of the Leds on X-NUCLEO-NFC04A1 board */

 NFC04A1_LED_Init( );

 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 */

UARTConsoleConfig();

UARTConsolePrint(uartmsg);

UARTConsolePrint("HELLO");

UARTConsolePrint( "----------------------------------------" );

 /* Init ST25DV driver */

 while( BSP_NFCTAG_Init( ) != NFCTAG_OK );

 /* Reset Mailbox enable to allow write to EEPROM */

 BSP_NFCTAG_GetExtended_Drv()->ResetMBEN_Dyn( );

  

 /* Check if no NDEF detected, init mem in Tag Type 5 */

 if( NfcType5_NDEFDetection( ) != NDEF_OK )

 {

  CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;

  CCFileStruct.Version = NFCT5_VERSION_V1_0;

  CCFileStruct.MemorySize = ( ST25DV_MAX_SIZE / 8 ) & 0xFF;

  CCFileStruct.TT5Tag = 0x05;

  /* Init of the Type Tag 5 component (M24LR) */

  while( NfcType5_TT5Init( ) != NFCTAG_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 );

  

 /* Prepare URI NDEF message content */

 strcpy( URI.protocol,URI_ID_0x01_STRING );

 strcpy( URI.URI_Message,"st.com/st25" );

 strcpy( URI.Information,"\0" );

  

 /* Write NDEF to EEPROM */

 while( NDEF_WriteURI( &URI ) != NDEF_OK );

  

 /* Set the LED3 on to indicate Programing done */

 NFC04A1_LED_ON( YELLOW_LED );

  

 /* Infinite loop */

 while (1)

 {  

 }

}

void UARTConsoleConfig( void )

{

 if(HAL_UART_GetState(&huart) == HAL_UART_STATE_RESET)

 {

  huart.Instance      = USART2;

  huart.Init.BaudRate   = 115200;

  huart.Init.WordLength  = UART_WORDLENGTH_8B;

  huart.Init.StopBits   = UART_STOPBITS_1;

  huart.Init.Parity    = UART_PARITY_NONE;

  huart.Init.Mode     = UART_MODE_TX_RX;

  huart.Init.HwFlowCtl   = UART_HWCONTROL_NONE;

  huart.Init.OverSampling = UART_OVERSAMPLING_16;

   

  HAL_UART_Init(&huart);

}

}

HAL_StatusTypeDef UARTConsolePrint( char *puartmsg )

{

 return HAL_UART_Transmit( &huart, (uint8_t *)puartmsg, strlen( puartmsg ), 500);

}

HAL_StatusTypeDef UARTConsoleScan( uint8_t uartchar )

{

 while( HAL_UART_Receive( &huart, &uartchar, 1, 500) == HAL_TIMEOUT );

  

 return HAL_OK;

}

#ifdef USE_FULL_ASSERT

void assert_failed( uint8_t* file, uint32_t line )

 /* Infinite loop */

 while( 1 )

 {

 }

}

#endif

11 REPLIES 11
Pooja Sain
Associate II

Hi Rene Lenerve,

Yes, now UART worked. My primary task has completed. Secondary task is still remaining and it is to prepare URI NDEF message content and NFC application would work. How to read/write the information through I2C in this RFID tag. This RFID tag supports I2C @1MHz . For that I have found I2C address of RFID tag using arduino scanner and the I2C addresses are -> 0x2D, 0x53, 0x57.

..................................................................................................................................................................................................................................

/* Prepare URI NDEF message content */

 strcpy( URI.protocol,URI_ID_0x01_STRING );

 strcpy( URI.URI_Message,"st.com/st25" );

 strcpy( URI.Information,"\0" );

......................................................................................................................................................................................................................................

I don't know how to use this URI information for NFC application through mobile. Appreciate your help.

Regards.

Rene Lenerve
ST Employee

Hi @Pooja Sain​ ,

You can find useful information in the Datasheet (https://www.st.com/resource/en/datasheet/st25dv04k.pdf), device address is in the section 6.3.

Address 0x53 is used to access user memory of the RFID Tag and address 0x57 to access system area. Please read the datasheet to understand this Product.

The Nfc4 software package includes basic examples and drivers for the ST25DV Tag. So you can find these various examples in it NDEF URI, Energy Harvesting, GPO, I²C Protection, LPD, Mailbox to help you developing your application.

This package also comes with an NDEF Library (NDEF_Lib in source files) which will allow you to format or read NDEF messages located in the Tag memory. In the NDEF URI example you have the example in how to write an NDEF URI to the Tag:

...
  /* Prepare URI NDEF message content */
  strcpy( URI.protocol,URI_ID_0x01_STRING );
  strcpy( URI.URI_Message,"st.com/st25" );
  strcpy( URI.Information,"\0" );
  
  /* Write NDEF to EEPROM */
  while( NDEF_WriteURI( &URI ) != NDEF_OK );
...

But you need to know at minima how is build the NDEF format (Help yourself from Google)

so for the read, it could be something like that:

...
  sRecordInfo_t record;
  uint8_t *p_ndef_buffer = ...; //pointer to sufficent memory space allocated for the NDEF
  sURI_Info r_uri;
 
  NDEF_ReadNDEF( p_ndef_buffer );
  NDEF_IdentifyBuffer( &record, p_ndef_buffer );
  
  /* To avoid displaying random memory content in case URI part is missing */
  r_uri.Information[0] = '\0';
  r_uri.protocol[0] = '\0';
  r_uri.URI_Message[0] = '\0';
  getNDEFRecord( &record );
 
  NDEF_ReadURI( &record, &r_uri );
...

But if you want to access directly to the Tag content or registers you can use driver functions available in BSP Drivers x_nucleo_nfc04a1.c and x_nucleo_nfc04a1_nfctag.c files.

Regards.