1

I have interfaced AT24c1024 EEprom with ATmega32.AT24c1024, which has 512 pages each of 256 bytes. There are two mode of writing (byte write and page write).

In page write mode, it is capable of writing 256 bytes for page; if we want to write 258 bytes, then the first two bytes in the beginning of that page will be overwritten.

My question is: what should I do to write in the whole EEprom (i.e) if I want to write 300 bytes, I want to writes 256 bytes in a page then continues to the next page and so on?

1

In that case you write two pages, the first page containing the first 256 bytes and the second page containing the following 34 bytes.

You can do a speed check to see if writing the second page's 34 bytes by using the byte write is faster, but I doubt that.

In case you want to keep from the second page the remainder of the 34 bytes (the 256-34 bytes following), you first read the second page, than you change the first 34 bytes, than write it back.

Also note that there is a limit on the number of writes on a page. This is called page wearing. So if you write these 2 pages very often, you might want to come up with an algorithm to rotate through all the available pages in your EEPROM, and not writing every time to the same 2 pages.

EXAMPLE

Assume you want to write totalBytesToWrite:

// Calculate the number of pages to write, round up.
int pagesToWrite = int((totalBytesToWrite + 255) / 256;

for (int page = 0; page < pagesToWrite; page++) // Current page to be written
{
    // Calculate number of bytes to be written in this page, for the last page, write remaining bytes, otherwise 256
    int pageBytesToWrite = (page == pagesToWrite - 1 ? totalBytesToWrite % 256 : 256; 

    // Write page (btw, I do not know what the second argument char deviceAddress means)
    page_write(n / 256, ??, &memory[n], pageBytesToWrite);
}
  • Dear sir,I want to use the page write mode,when I use it to write 300 byte,it will write the first 256 bytes in that page and then overwrite the first 34 bytes in the same page to write the rest 34 bytes....my question..how to continue to write these 34 bytes in the next page? – mohamed Jul 14 at 13:16
  • If you overwrite the 34 bytes in the same page you lose the before written 256 bytes (is that what you want?) ... in the function for writing data to the page I guess there is a page number, can you give the link of the API (functions) for that EEPROM (the library you use) ? – Michel Keijzers Jul 14 at 13:30
  • The function containing the staring address you want to write from... – mohamed Jul 14 at 13:36
  • To write 'to' you mean? – Michel Keijzers Jul 14 at 13:38
  • The address you want to start writing data from it – mohamed Jul 14 at 13:39

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.