cancel
Showing results for 
Search instead for 
Did you mean: 

M24Sr02 Read and Write Problem(I2C)

Anish Venkataraman
Associate II
Posted on June 21, 2018 at 20:37

Hello Everyone!

I am currently using the dynmaic nfc tag M24SR02-Y and I am facing problems with it while communicating with I2C. I get all the correct responses but when i try to read the NDEF length something goes wrong. I would appreciate if someone could help me out with this issue, I have been coding it for 2 days now and nothing seems to work.

Here are my commands with Responses:

//Send 'Kill RF and open I2C

  Send AC 52

  //Select NFC-T4

  AC 02 00 A4 04 00 07 D2 76 00 00 85 01 01 00 CRC CRC

  //Read back answer from M24SR

  Write AD, READ 02 90 00 CRC CRC

  // select CC

  AC 03 00 A4 00 0C 02 E1 03 CRC CRC

  //Read back answer from M24SR

  Write AD Read 03 90 00 CRC CRC

  //Read CC file-length

  AC 02 00 B0 00 00 02 CRC CRC

  //Read back answer from M24SR

  Write AD Read 02 00 0F 90 00 CRC CRC

  //Read CC file

  AC 03 00 B0 00 00 0F CRC CRC

  //Read back answer from M24SR

  Write AD Read 03 00 0F 20 00 F6 00 F6 04 06 00 01 01 00 00 00 90 00 CRC CRC

Write commands

 

//Select NDEF file

 

  AC 02 00 A4 00 0C 02 00 01 CRC CRC

 

 

  Write AD Read 02 90 00 CRC CRC

 

 

 

 

 

  //Erase NDEF message length

 

  AC 02 00 A4 00 0C 02 00 01 CRC CRC

 

 

  Write AD Read 03 90 00

 

 

 

 

  //Write NDEF message

Wrote AC 02 00 D6 00 02 0D D1 01 09 54 02 65 6E 4E 69 63 6B 65 21 21 CRC CRC

Read 03 09 00 CRC CRC

//Write NDEF length

AC 03 00 D6 00 00 02 00 0E CRC CRC

  Write AD Read 02 90 00 CRC CRC

//Deselect command

AC C2 CRC CRC

when i remove supply and place my phone on top of the antenna the tag reads 0 bytes/255. What am I doing wrong?

:(

To verify the write was successful I added  read commands as well.

Read Commands

//Select NDEF file

  AC 02 00 A4 00 0C 02 00 01 CRC CRC

  //Read back answer from M24SR

  Write AD Read 02 90 00 CRC CRC

  //Read NDEF message length

  AC 03 00 B0 00 00 02 CRC CRC

  Write AD Read 03 00 0f 90 00 44 45 Similar to the response of CC file length but length shows '0x0f' whereas written is 0E 

and when I try to read the data it is similar to contents of CC file. Please help me.

Thanks in advance.

#i2c-isues #m24sr #nfc-tags #m24sr-i2c
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on June 22, 2018 at 17:16

Hi Anish,

Looking into your m24sr.txt file, one thing I noticed that makes an error, when trying to reproduce your sequence, is the length of data in function testWrite and writeNDEFLength. The length of your NDEF is 14 bytes, so you should set the length to 0x0E (and

therefore change the CRC also).

Here after are the fixed functions:

void testWrite(void){
 
 I2CStart();
 I2CSlaveAddress(M24SR_I2C_ADDR);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0xD6);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x0E);//fixed size value
 I2CWriteSingle(0xD1);
 I2CWriteSingle(0x01);
 I2CWriteSingle(0x09);
 I2CWriteSingle(0x54);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x65);
 I2CWriteSingle(0x6E);
 I2CWriteSingle(0x4E);
 I2CWriteSingle(0x69);
 I2CWriteSingle(0x63);
 I2CWriteSingle(0x6B);
 I2CWriteSingle(0x65);
 I2CWriteSingle(0x21);
 I2CWriteSingle(0x21);
 I2CWriteSingle(0x21);//updated CRC value
 I2CWriteSingle(0x9D);//updated CRC value
 I2CStop();
 __delay_ms(1000);
 ReceiveResponse(1);
}
void writeNDEFLength(void){
 
 I2CStart();
 I2CSlaveAddress(M24SR_I2C_ADDR);
 I2CWriteSingle(0x03);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0xD6);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x0E);//fixed size value
 I2CWriteSingle(0x15);//updated CRC value
 I2CWriteSingle(0xDE);//updated CRC value
 I2CStop();
 __delay_ms(10);
 ReceiveResponse(1);
 
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Hope this can help you.

Regards.

View solution in original post

13 REPLIES 13
Berenice BENVEGUDA
ST Employee
Posted on June 22, 2018 at 09:14

Hello Anish,

First of all thanks for your interest in M24SR02 product !

Then, I can see two reasons explaining the misbehaviour :

when you try to erase the NDEF length :

 

//Erase NDEF message length

  AC 02 00 A4 00 0C 02 00 01 CRC CRC

 

-> in fact you redo a select ndef file

can you please replace this command by : AC 02 00 D6 00 00 02 00 00 CRC CRC ?

Then when you rewrite the ndef length you progamm 00 0E but you have written 0D data in the previous command . Could you try the rewrite the ndef length to 00 0D instead ?

Hope this helps,

Best Regards,

BB

Posted on June 22, 2018 at 11:46

Thank you for the reply! The erase data command that I wrote in the code had D6 it's a typo error. Also could you please tell me the exact setting for GPO pin as I have just added a 10k pull-up resistor to it. Do I have to send some specific commands for it?

ThabTh

Posted on June 22, 2018 at 13:48

Hello Anish,

To program the GPO you have to program the address 0x0004 of the system file depending on which event you want to observe.

Please refer to chapter 2.7 and 3.1.4 of the datasheet at the link below :

https://www.st.com/content/st_com/en/products/nfc/st25-nfc-rfid-tags-readers/st25-dynamic-nfc-tags/m24sr-series-dynamic-nfc-tags.html?querycriteria=productId=SS1812

 

Hope this helps,

Best Regards,

BB

Posted on June 22, 2018 at 14:25

I hadn't configured the GPO pin at all. Could that be the reason for those responses I was getting while sending the readNdef length command?

Posted on June 22, 2018 at 14:43

Hi Anish,

GPO is configured by default to 0x11 (Message in Progress), so the issue does not come from here.

Could you try to remove deselect command before switching off Vcc, please ?

Moreover, could you tell me which phone you use, please ? what application do you use to read the content of your tag ? What kind of message do you get on your phone when you try to read, please?

Best Regards,

BB

Posted on June 22, 2018 at 15:23

Hi Berenice,

Thank you so much for helping me in this. I am using NFC tool application on Samsung Galaxy S8.I get basic information about the tag like the UID number, tag info, number of bytes written, data etc.

Now after changing the length as per you mentioned, I am getting the response for read NDEF length as 0x12, also read NDEF data gives me the same response for read CC file contents. I am a bit confused now. And one more thing should the first byte of every command toggle between 0x02 and 0x03?

Posted on June 22, 2018 at 15:54

I am really sorry to bother you but could please take a look at my file and tell me where I am going wrong. I am getting all the correct responses for the command i send except for reading length and data of NDEF file.

The operation of commands is in this order:

M24SROpenSession();

selectNDEFTagApplication();

selectSystemFile();

readSystemFileLength();

readSystemFileData();

verifyWritePassword();

setGPOFIeld();

selectSystemFile_1();

readSystemFileLength();

readSystemFileData();

selectNDEFTagApplication();

selectCCFile();

readCCFileLength();

readCCFile();

selectNDEFFile();

//Write

// clearNDEFLength();

// testWrite();

// writeNDEFLength();

//deselectI2C();

//Read

readNDEFLength();

readNDEFFileData();

// deselectI2C();

________________

Attachments :

m24sr.txt.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxQt&d=%2Fa%2F0X0000000ayb%2FO4ks01m2iDdyvDTUaIa4Mytc41gm8aQbnqb.lVIBI50&asPdf=false
Posted on June 22, 2018 at 15:56

Hi Anish,

Could you tell me which version of Android application you have on your phone please ?

and concerning, the byte 0x02 and 0x03, this is a synchronisation bit between the reader and the tag, it is the standard. The tag shall answer with the same parity bit as the previous command it has just received.

so if the command has been sent beginning with AC 02, the tag should answer beginning with 02 as well, otherwise the answer will be ignored or it can mean the tag has not understood the command. Moreover the reader should alternate commands sent with 02 and 03.

Hope this helps for debug,

Best Regards,

BB

Posted on June 22, 2018 at 17:16

Hi Anish,

Looking into your m24sr.txt file, one thing I noticed that makes an error, when trying to reproduce your sequence, is the length of data in function testWrite and writeNDEFLength. The length of your NDEF is 14 bytes, so you should set the length to 0x0E (and

therefore change the CRC also).

Here after are the fixed functions:

void testWrite(void){
 
 I2CStart();
 I2CSlaveAddress(M24SR_I2C_ADDR);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0xD6);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x0E);//fixed size value
 I2CWriteSingle(0xD1);
 I2CWriteSingle(0x01);
 I2CWriteSingle(0x09);
 I2CWriteSingle(0x54);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x65);
 I2CWriteSingle(0x6E);
 I2CWriteSingle(0x4E);
 I2CWriteSingle(0x69);
 I2CWriteSingle(0x63);
 I2CWriteSingle(0x6B);
 I2CWriteSingle(0x65);
 I2CWriteSingle(0x21);
 I2CWriteSingle(0x21);
 I2CWriteSingle(0x21);//updated CRC value
 I2CWriteSingle(0x9D);//updated CRC value
 I2CStop();
 __delay_ms(1000);
 ReceiveResponse(1);
}
void writeNDEFLength(void){
 
 I2CStart();
 I2CSlaveAddress(M24SR_I2C_ADDR);
 I2CWriteSingle(0x03);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0xD6);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x02);
 I2CWriteSingle(0x00);
 I2CWriteSingle(0x0E);//fixed size value
 I2CWriteSingle(0x15);//updated CRC value
 I2CWriteSingle(0xDE);//updated CRC value
 I2CStop();
 __delay_ms(10);
 ReceiveResponse(1);
 
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Hope this can help you.

Regards.