cancel
Showing results for 
Search instead for 
Did you mean: 

Write in NFC01A1 memory by i2c protocol in Python

TDufo.1
Associate

Hi, I work on the NFC01A1 and want to write in the M24SR with i2c protocol in python. My goal is to put a URI in, "abc.com" in this example. Here, I will put only the 3 important parts of the code, Erase Message Length, Write Message, Write Message Length :

# erase NDEF messgae length
    wait("erase NDEF message length")
    data = [0x03,0x00,0xD6,0x00,0x00,0x02,0x00,0x00]
    tag.write(data, crc=True)
 
    # write NDEF  message 
    wait ("write NDEF message")
    data = [0x02,0x00,0xD6,0x00,0x02,0x0C,0xD1,0x01,0x07,0x55,0x03,0x61,0x62,0x63,0x2E,0x63,0x6F,0x6D]
    tag.write(data, crc=True)
    
    # write NDEF message length
    wait("write NDEF message length")
    data = [0x03,0x00,0xD6,0x00,0x00,0x02,0x00,0x08]
    tag.write(data, crc= True)

I can read it with the applcation ST25 NFC tap, I got this :

0693W000001sv5KQAQ.jpg

I think I can't open the page because of the two bytes "00 08" and I don't really now why they are here..

Do you have any solution for this problem ?

Thank you all !

1 ACCEPTED SOLUTION

Accepted Solutions
Olivier L
ST Employee

Hi,

  # erase NDEF messgae length
  wait("erase NDEF message length")
  data = [0x03,0x00,0xD6,0x00,0x00,0x02,0x00,0x00]

Did you send this command to write an Empty NDEF?

The recommended empty NDEF is 0x00 0x03 0xD0 0x00 0x00.

In your dump, I see the bytes 0x03 0x00 for the length and I’m wondering if you may have done an error with the endianess: NFC Forum specification uses the Big Endian standard so the first byte is the MSB. If the length is “3 bytes�? you should write 0x00 0x03.

That’s a good thing that you do the NDEF programming in 3 steps. This is indeed what should be done. I’m sharing with you the Android log showing what is written in the tag when saving the URI “abc.com�?:

- First we have a command to select the NDEF File (File Id = 0x0001):

2020-07-15 14:06:26.262 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send SelectFile 0x0001 command: 00 a4 00 0c 02 00 01

2020-07-15 14:06:26.268 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

- Then we write 0x00 0x00 in the NDEF Length:

2020-07-15 14:06:26.268 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send updateBinary command: 00 d6 00 00 02 00 00

2020-07-15 14:06:26.277 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

- Then we write the NDEF message:

2020-07-15 14:06:26.278 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send updateBinary command: 00 d6 00 02 0c d1 01 08 55 01 61 62 63 2e 63 6f 6d

2020-07-15 14:06:26.289 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

NB: We write from the offset 0x02 so, at this stage the length is still 0x00 0x00

- Then we write the correct NDEF length:

2020-07-15 14:06:26.290 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send updateBinary command: 00 d6 00 00 02 00 0c

2020-07-15 14:06:26.299 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

Here is what we get in the memory at the end: 00 0c d1 01 08 55 01 61 62 63 2e 63 6f 6d

I think that you can do the same from I2C.

Concerning the dump shown on the last picture (the one starting with 0xD1), I have noticed that you miss the 2 bytes indicating the NDEF length.

Best regards

View solution in original post

3 REPLIES 3
Olivier L
ST Employee

Hi,

  # erase NDEF messgae length
  wait("erase NDEF message length")
  data = [0x03,0x00,0xD6,0x00,0x00,0x02,0x00,0x00]

Did you send this command to write an Empty NDEF?

The recommended empty NDEF is 0x00 0x03 0xD0 0x00 0x00.

In your dump, I see the bytes 0x03 0x00 for the length and I’m wondering if you may have done an error with the endianess: NFC Forum specification uses the Big Endian standard so the first byte is the MSB. If the length is “3 bytes�? you should write 0x00 0x03.

That’s a good thing that you do the NDEF programming in 3 steps. This is indeed what should be done. I’m sharing with you the Android log showing what is written in the tag when saving the URI “abc.com�?:

- First we have a command to select the NDEF File (File Id = 0x0001):

2020-07-15 14:06:26.262 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send SelectFile 0x0001 command: 00 a4 00 0c 02 00 01

2020-07-15 14:06:26.268 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

- Then we write 0x00 0x00 in the NDEF Length:

2020-07-15 14:06:26.268 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send updateBinary command: 00 d6 00 00 02 00 00

2020-07-15 14:06:26.277 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

- Then we write the NDEF message:

2020-07-15 14:06:26.278 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send updateBinary command: 00 d6 00 02 0c d1 01 08 55 01 61 62 63 2e 63 6f 6d

2020-07-15 14:06:26.289 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

NB: We write from the offset 0x02 so, at this stage the length is still 0x00 0x00

- Then we write the correct NDEF length:

2020-07-15 14:06:26.290 10839-10883/com.st.st25nfc.dbg D/Type4Command: ==> Send updateBinary command: 00 d6 00 00 02 00 0c

2020-07-15 14:06:26.299 10839-10883/com.st.st25nfc.dbg D/Type4Command: Response: 90 00

Here is what we get in the memory at the end: 00 0c d1 01 08 55 01 61 62 63 2e 63 6f 6d

I think that you can do the same from I2C.

Concerning the dump shown on the last picture (the one starting with 0xD1), I have noticed that you miss the 2 bytes indicating the NDEF length.

Best regards

TDufo.1
Associate

Thank you for your quick reply,

So, yes I use this code to write an empty NDEF to start. I will try with your recommendations and let you know what it changes.

By reading your text, I got a fault on one byte of the code, the last byteof "Write the correct NDEF length. I wrote "0x08" instead of "0x0C" and now, all is functionning perfectly. The first two bytes are 00 0C.

Best regards

Olivier L
ST Employee

Good! Your going into the right direction.

Best regards