1
\$\begingroup\$

Im trying to read/write EEPROM byte by byte but if i dont put an enough delay(~1ms) between read/write tasks, im getting or writing wrong value to the EEPROM. But this delay is taking a significant time when there is a many bytes to read/write and 400kHz losing its meaning. Am i missing something ? or its a nature of byte by byte process is slow. Thanks for your time and help.

MCU = STM32F072C8Tx

EEPROM = 24LC64

I2C Settings:

 Speed = 400 kHz
 Rise Time = 300 ns
 Fall Time = 300 ns
 Analog Filter = Disable
 Digital Filter Coefficent = 0

Basic R/W Code Sample:

 HAL_I2C_Mem_Write(&hi2c1, device_addr, mem_addr, I2C_MEMADD_SIZE_16BIT, data, 1, 500);
 Hal_Delay(1);
 HAL_I2C_Mem_Read(&hi2c1, device_addr, mem_addr, I2C_MEMADD_SIZE_16BIT, databuffr, 1, 500);
\$\endgroup\$
1
3
\$\begingroup\$

Yes, you are missing the time it takes to write anything, even if the bus is 400kHz.

The first page of 24LC64 says that a page write is max 5ms. You can write one byte or up to 32 bytes (a full page) at once but it can still take up to 5ms.

So after a write operation, the EEPROM will be busy writing the data and will not respond to any operation until it is finished with the write.

\$\endgroup\$
2
  • \$\begingroup\$ It seems your answer approves the "nature of byte by byte process is slow" ? \$\endgroup\$
    – U.Sim
    Mar 9 at 11:46
  • \$\begingroup\$ Yes. And for every single byte you write, the chip must internally erase a full 32-byte page, and write back the whole page with modified contents. So if you write single bytes in a for loop, the whole page gets erased and rewritten many times. \$\endgroup\$
    – Justme
    Mar 9 at 12:04
4
\$\begingroup\$

EEProms require some minimum amount of time to write a page or single byte to memory. Most production code will poll the device (WB bit) to see when this write has finished. In your case, the 1ms probably allows this time to finish.

It is going to be more efficient to write by pages rather than bytes, you only have to wait one time, rather than for each byte. Watch that you don't wrap pages. Page size is going to be some power of 2, see datasheet for exact size.

\$\endgroup\$
1
  • \$\begingroup\$ Page writes are not only faster, but will wear out the chip slower. EEPROMs have a limited number of writes before they wear out. \$\endgroup\$
    – Mattman944
    Mar 9 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.