cancel
Showing results for 
Search instead for 
Did you mean: 

Reading and writing problems (over I2C)

na
Associate II
Posted on February 17, 2015 at 09:49

Hello,

I can't get either read or write (over I2C) to work correct.

If I write the text ''Hello World!!'' from the phone (S3) and then read it over the I2C I get the following error.

When I read the length it says 0x14, but if I try to read anything over 0x10 it will fail (only sending FF...), but if I read only 0x10 (or less) it will work?!

Same when I try to write (over the I2C), then I will get the error code 67 00, but I can't see what's wrong.

If I read it with the phone it says it's empty, but if I read it over the I2C I can find it there.

Below is a summery over what I send (and get back) over the I2C.

Anyone that can tell me what I'm doing wrong?

Grateful for help!

void InitNFC()

{

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

} // Init done   

      

void ReadNFC()

{

  //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 14 90 00 CRC CRC

 

  //Read NDEF message

  AC 02 00 B0 00 02 10 CRC CRC    //Length 14 does not work, 0 to 10 works (I get some of the answer), but over 10 will cause answer to all FF

  Write AD Read 02 D1 01 10 54 02 65 6E 48 65 6C 6C 6F 20 57 6F 72 90 00 CRC CRC

 

  //Send Deselect

  AC C2 CRC CRC  

  Write AD Read C2 CRC CRC  

} // ReadNFC done

void WriteNFC()

{

  initNFC()

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

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

  Write AD Read 67 00 CRC CRC

 

  //Write NDEF message length

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

  Write AD Read FF FF FF FF FF

 

  //Send Deselect

  AC C2 CRC CRC

  Write AD Read C2 CRC CRC

} //WriteNFC done

void main (void){

 initNFC()

 ReadNFC()

 WriteNFC()

}
1 ACCEPTED SOLUTION

Accepted Solutions
na
Associate II
Posted on March 12, 2015 at 21:01

Solved! Thanks to Wen-Kai, who helped me to find the solution.

The trick was to add a small delay between the write and read of the NDEF message.

//Read NDEF message

  AC 02 00 B0 00 02 10 CRC CRC  

// add a delay here of more then 10us (for me it worked with 50us, but 100-300us might be needed in some cases.

  Write AD Read 02 D1 01 10 54 02 65 6E 48 65 6C 6C 6F 20 57 6F 72 90 00 CRC CRC

 

/Nicklas

View solution in original post

1 REPLY 1
na
Associate II
Posted on March 12, 2015 at 21:01

Solved! Thanks to Wen-Kai, who helped me to find the solution.

The trick was to add a small delay between the write and read of the NDEF message.

//Read NDEF message

  AC 02 00 B0 00 02 10 CRC CRC  

// add a delay here of more then 10us (for me it worked with 50us, but 100-300us might be needed in some cases.

  Write AD Read 02 D1 01 10 54 02 65 6E 48 65 6C 6C 6F 20 57 6F 72 90 00 CRC CRC

 

/Nicklas