# How to effectively tackle long page write in EEPROM

I'm using C18 compiler and 24LC256 EEPROM. I would like to know how to handle Rollover case in terms of large EEPROM write.I'm writing a Routine that writes 120 Bytes every half an hour and i would like to know how can i save/store my data easily as Page Write will take only 5 ms as equal to a single write operation.The Page size here is 64 Bytes.And i have to write for 10 hours making it 2.4 K space per day.

Well the problem i have is:

1.I want to use Page Write Efficiently and wants to prevent Roll over condition. page size starts from 0-63 , 64-127 ,128-191,192-255...up to 32 K. I want to Predict when is the Page Limit coming and wants the Page Write to shift accordingly.

eg: If i start with 0th address: 0-63 will occupy 64 bytes and 64-117 will occupy the next 56 Bytes. Then for the next Page Write i can only write 20 locations and have to write 64 and 20 in another two Page Write Operations.

Note:Dedicating starting Page Locations for each Page Write is not required.

Page write operations are limited to writing
bytes within a single physical page,
regardless of the number of bytes actually
being written. Physical page boundaries
start at addresses that are integer
multiples of the page buffer size (or ‘page
size’) and end at addresses that are
integer multiples of [page size - 1]. If a
Page Write command attempts to write
across a physical page boundary, the
result is that the data wraps around to the
beginning of the current page (overwriting
data previously stored there), instead of
being written to the next page, as might be
expected. It is, therefore, necessary for the
application software to prevent page write
operations that would attempt to cross a
page boundary


I have been trying to find an algorithm to do so. It would be extremely helpful if you sort out this issue or suggest your insights.

Regards

Arookie

• Wouldn't it be much simpler to always write your 120 bytes to two pages? You don't seem to be size-constrained. – Wouter van Ooijen Jan 15 '14 at 9:26
• Well i'm pretty much size constrained here.I was just trying to get a method to find an apt method here to fix the problem. – Rookie91 Jan 15 '14 at 9:34
• I don't see your problem. For every byte you write you increment a counter, when it reaches 64 you do a page write and set the counter to 0. – Wouter van Ooijen Jan 15 '14 at 10:11
• Thank you @Wouter van Ooijeb What if it crosses the page boundary.It can cause a problem right. – Rookie91 Jan 15 '14 at 10:33
• When you cross the page boundary the address rolls over to the first location of the page and you overwrite the value there. – alexan_e Jan 15 '14 at 10:36

What Wouter van Ooijen has suggested does perfect sense.

This should work

uint8_t page_counter=0;
uint8_t data_counter=0;

while(data_counter<120)  // we want to write 120 bytes
{