cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to and reading from ST25DV04KC through i2c.

baranovus
Associate III

Hello ALL.

I am reading this from the ST25DV04KC datasheet:

"During the internal write cycle, the device disconnects itself from the bus, and writes a copy of the data from its
internal latches to the memory cells. The maximum I²C write time (tw) is shown in Table 251. I²C AC
characteristics up to 85 °C and Table 252. I²C AC characteristics up to 125 °C, but the typical time is shorter."

The value of I²C write time in Table 251 is ~5 ms.

I wrote a test function, which writes a 16-byte array to the user memory and tries to read it back. I really see that if the delay between writing and reading is about 800 us, reading fails because I don't get ACK. It works if I write and read e.g. from two separate console commands.

Are my observations right, and is it really necessary to wait for ~5ms or do ACK polling tests or do I have a bug in my code?

Thanks.

2 REPLIES 2
JL. Lebon
ST Employee

Hello, 

"I wrote a test function, which writes a 16-byte array to the user memory and tries to read it back. I really see that if the delay between writing and reading is about 800 us, reading fails because I don't get ACK" -> what you observe is correct. After the STOP condition of your write command, the device will program the EEPROM during 5ms. During this time, it is not accessible, meaning the any I2C command (read or write) will be NACK'ed.
The read command 800us after the write is NACK'ed for this reason.

"It works if I write and read e.g. from two separate console commands." -> I'm not sure exactly what you mean by that, but it is possible that the two separate commands you sent are separated by more than 5ms, which explains why it is working.

And yes, it is really necessary to wait for the end of programming time to access the device again.

After an I2C write into the EEPROM memory, you can do 3 different things:
- wait for more than tw before issuing a new I2C command (tw must be multiplied by the number of EEPROM rows programmed).
- poll for the availability of the I2C bus, by sending regular I2C write command without data (e.g. START/A6h/STOP). As long as the poll command is NACK'ed, it means the programming is still on-going. When the poll command is ACK'ed, it means the programming is completed and the tag is ready to receive a new read or write command.
- last possibility is to use the I2C_WRITE interrupt. If this interrupt is enabled, the ST25DV04KC will generate an interrupt at the end of the programming time, so the MCU is directly informed that the I2C bus is available again without any polling of blocking wait.

Best regards.

Thanks!