7
\$\begingroup\$

I am using an M24C64 EEPROM with an STM32F4, but I have a problem with sequential writing. When I try to write 16-bit data sequentially like this, I get HAL_I2C_ERROR_AF error:

write_eeprom(address1,data1);
write_eeprom(address2,data2);

But if I put a 5 ms delay between write operations, I could write successfully.

How can I write faster to the EEPROM?

\$\endgroup\$
13
\$\begingroup\$

Some sort of delay is required because the device is busy writing the data.

The datasheet for this device gives you two options to minimize it:

  • page writes (section 5.1.2) to write 32 bytes at a time
  • polling instead of using a fixed, worst-case delay of 5ms (section 5.1.6)

If you do page writes, be careful that your addresses are aligned with page boundaries, otherwise the device will silently corrupt the data.

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for your explanations, if I use the page write, When I read do I have to page read? \$\endgroup\$
    – gogogo
    Jul 2 at 5:58
  • 3
    \$\begingroup\$ You can use any method to read the data, it doesn't remember how it was written. The different methods are all explained in the datasheet. \$\endgroup\$
    – DamienD
    Jul 2 at 8:16
5
\$\begingroup\$

You can't write single bytes any faster. Each write operation to a page takes up to 5ms to complete.

However, what you can do is to write multiple bytes into a page, as the chip has a page size of 32 bytes.

So each write of up to 32 bytes within a page takes up to 5ms.

\$\endgroup\$

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.