cancel
Showing results for 
Search instead for 
Did you mean: 

NDEF writing/reading via I2C in X-Nucleo- NFC04A1(ST25DV)

NewOne
Associate

Hi I'm trying to write text via NDEF library to be available to read from EEPROM by phone nfc aplication. Also I want to read text send by phone directly to EEPROM. I tried to change NDEF_URI example method to implement NDEF_WriteText and NDEF_ReadText method and write some text into ST25DV EEPROM and read from but honestly I have no idea what's wrong with my conception. Could you show me some code where you are using these methods?

1 ACCEPTED SOLUTION

Accepted Solutions
Rene Lenerve
ST Employee

Hi @NewOne​ ,

Here is a simple example to write a simple Text NDEF message and read it after.

  /* Init ST25DV driver */
  while( NFC04A1_NFCTAG_Init(0) != NFCTAG_OK );
 
  /* Reset Mailbox enable to allow write to EEPROM */
  NFC04A1_NFCTAG_ResetMBEN_Dyn(0);
 
  NfcTag_SelectProtocol(NFCTAG_TYPE5);
 
  /* Check NDEF presence, if no init mem in Tag Type 5 */
  if( NfcType5_NDEFDetection( ) != NDEF_OK )
  {
  /* If CCFile is not present add it to memory */
    CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;
    CCFileStruct.Version = NFCT5_VERSION_V1_0;
    CCFileStruct.MemorySize = ( ST25DV_MAX_SIZE / 8 ) & 0xFF; // ST25DV_MAX_SIZE = 0x200 => 4Kb memory
    CCFileStruct.TT5Tag = 0x01;
    /* Init of the Type Tag 5 component */
    while( NfcType5_TT5Init( ) != NFCTAG_OK );
  }
 
  /* write text message to EEPROM */
  while( NDEF_WriteText( "NDEF Text message" ) != NDEF_OK );
  
  NDEF_Text_info_t Text;
  sRecordInfo_t record;
  uint8_t p_ndef_buffer[64];
  
  /* read NDEF file */
  NDEF_ReadNDEF(p_ndef_buffer);
  /* Extract record info */
  NDEF_IdentifyBuffer(&record,p_ndef_buffer);
  
  /* Read Text in record */
  NDEF_ReadText( &record, &Text );

Hope this could help you.

Regards.

View solution in original post

35 REPLIES 35
Rene Lenerve
ST Employee

Hi @NewOne​ ,

Here is a simple example to write a simple Text NDEF message and read it after.

  /* Init ST25DV driver */
  while( NFC04A1_NFCTAG_Init(0) != NFCTAG_OK );
 
  /* Reset Mailbox enable to allow write to EEPROM */
  NFC04A1_NFCTAG_ResetMBEN_Dyn(0);
 
  NfcTag_SelectProtocol(NFCTAG_TYPE5);
 
  /* Check NDEF presence, if no init mem in Tag Type 5 */
  if( NfcType5_NDEFDetection( ) != NDEF_OK )
  {
  /* If CCFile is not present add it to memory */
    CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;
    CCFileStruct.Version = NFCT5_VERSION_V1_0;
    CCFileStruct.MemorySize = ( ST25DV_MAX_SIZE / 8 ) & 0xFF; // ST25DV_MAX_SIZE = 0x200 => 4Kb memory
    CCFileStruct.TT5Tag = 0x01;
    /* Init of the Type Tag 5 component */
    while( NfcType5_TT5Init( ) != NFCTAG_OK );
  }
 
  /* write text message to EEPROM */
  while( NDEF_WriteText( "NDEF Text message" ) != NDEF_OK );
  
  NDEF_Text_info_t Text;
  sRecordInfo_t record;
  uint8_t p_ndef_buffer[64];
  
  /* read NDEF file */
  NDEF_ReadNDEF(p_ndef_buffer);
  /* Extract record info */
  NDEF_IdentifyBuffer(&record,p_ndef_buffer);
  
  /* Read Text in record */
  NDEF_ReadText( &record, &Text );

Hope this could help you.

Regards.

Schuyler
Senior

Hello, I wrote an NDEF message with your reference code, but the phone did not read any messages.0693W00000aJA08QAG.png

Rene Lenerve
ST Employee

Hello,

When you say "the phone did not read any message", you mean without an application (natively)?

In that case NDEF Text message are not recognized by Android (or iOS) stack. Natively Android will work with URL, Bluetooth, Wifi, …. For other NDEF you will need an application, you can try the ST25 NFC Tap available on google play store and Apple store.

Hope this can help you.

Kind Regards.

Schuyler
Senior

hello.Do I only need to download the app to read text messages? So the above code provided can be read correctly, right?

Schuyler
Senior

I wish you can help me check if the code can implement this feature, is there a bug?

Schuyler
Senior

@Rene Lenerve​

I wish you can help me check if the code can implement this feature, is there a bug?

I still can't read NDEF messages using app0693W00000aJUmRQAW.jpg

Rene Lenerve
ST Employee

Hi @帅 罗​,

I think your issue come from this line (106):

CCFileStruct.MemorySize = 0x00;

with that you are saying that the tag's memory size is 0, which result in the St25 App to display no data in NDEF field. A value of 0x40 represent 4Kbits (512 Bytes). It can be another value of course.

Another point to update may be the type for the Text variable, for me it's compiling with NDEF_Text_info_t as type.

Let me know if that helps you.

Kind Regards.

Schuyler
Senior

Hi

I have modified the code according to what you said. Could you please help me to see if it is possible to read NDEF information

0693W00000aJYIQQA4.png

Rene Lenerve
ST Employee

Hi @帅罗.1 (Community Member)​,

You need to erase the memory of the Tag to rewrite the CC file, because with this code the NDEF detection doesn't enter the NfcTyp5_TT5Init process and CCFile keeps the old values.

You can perform this by erasing the tag memory with the NFC Tap App or in debug mode on the nucleo board by jumping the line "if ( NfcTyp5_NDEFDetection() != NDEF_OK )"

Kind Regards.