Skip to main content
Visitor II
November 29, 2019
Solved

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

  • November 29, 2019
  • 35 replies
  • 4436 views

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?

    This topic has been closed for replies.
    Best answer by Rene Lenerve

    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.

    35 replies

    ST Employee
    March 23, 2023

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

    I suggest you to erase the tag memory because if the CC file is already written it will not be updated with the code used above, and it is probably why you are not seeing the NDEF Text message in ST25 NFC App. By erasing the tag memory and use the code above it will automatically rewrite the CC file and the NDEF Text message. You are free to manage this part as you want.

    Kind Regards

    Explorer
    March 23, 2023

    Hi,

    This is shown below after I erase the tap memory through the application,so I will get the message by “NDEF editor�? or “read memory�?

    0693W00000aJZxyQAG.png0693W00000aJZywQAG.png

    ST Employee
    March 23, 2023

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

    Your screenshots are not displaying same tag content ST25DV vs ST25TA02K-P.

    For the ST25DV the CCFile has been correctly filled with expected values, the rest of the memory indicates that an empty message is stored. So now the NDEF Text message can be correctly written and then you should see it on the App.

    Kind Regards.

    Explorer
    March 24, 2023

    Hi @Rene Lenerve​ 

    I see what you mean,as for me,I think the first step is to clear the information in the memory,so the app's read memory will show 00. Then run the above code, can you read the NDEF message correctly by“read memory�? or "NDEF editor’?

    Explorer
    March 28, 2023

    Hi,@Rene Lenerve​ 

    I used the sample code called “NDEF_URI�? in X-CUBE-NFC7. But the phone still hasn't read the URL in the code, what should I do? 0693W00000aJr14QAC.png0693W00000aJr1JQAS.jpg

    Explorer
    March 28, 2023

     I have changed “MemorySize = 0x00�? to “CCFileStruct.MemorySize = (ST25DVXXKC_MAX_SIZE / 8) & 0xFF;�?

    ST Employee
    March 28, 2023

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

    I'm sorry, I'm not able to translate your screenshot.

    But the memory seems to be empty, if you have played the firmware it should have filled it with CCFile and NDEF message. This may be an issue with the NFC07A1_NFCTAG_Init function which checks that the connected component is an ST25DVxxKC. Are you sure that the chip is a ST25DVxxKC and not a ST25DVxxK?

    Kind Regards,

    Explorer
    March 28, 2023

    Hi,@Rene Lenerve​ 

    Yes,  the memory is empty, I can write to and read from memory from my phone,but the above code does not display the information correctly. I have checked ST25DVXXKC according to your prompt and found no problem,The memory read by the phone is always empty. Do you have a better suggestion0693W00000aJrmeQAC.png

    ST Employee
    March 28, 2023

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

    On my side the NFC7 code is working correctly and the update for the Text message too. I suggest that you run the code in debugging and check step by step to see where the error is.

    Kind regards.

    Explorer
    March 28, 2023

    The NFC7 code you use is “en.x-cube-nfc7�? and I didn't make any changes? Can I see a screenshot that shows up correctly?