# Sequential EEPROM writing

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);


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

How can I write faster to the EEPROM?

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.

• Thank you for your explanations, if I use the page write, When I read do I have to page read? Jul 2, 2021 at 5:58
• 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. Jul 2, 2021 at 8:16

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.