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);
asked Mar 9, 2021 at 11:16
\$\endgroup\$
1

2 Answers 2

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.

answered Mar 9, 2021 at 11:35
\$\endgroup\$
2
  • \$\begingroup\$ It seems your answer approves the "nature of byte by byte process is slow" ? \$\endgroup\$ Commented Mar 9, 2021 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\$ Commented Mar 9, 2021 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.

answered Mar 9, 2021 at 11:28
\$\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\$ Commented Mar 9, 2021 at 13:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.