ATmega1280: 4 KB of EEPROM Is Not a Small Flash
A hundred-pin microcontroller with 128 KB of flash, 8 KB of SRAM and 4 KB of EEPROM invites a comparison that is intuitively appealing and wrong: that the EEPROM is a small flash array, so the two can be treated as one memory of 132 KB. They cannot, and the reason is not the capacity. It is that they are addressed by different mechanisms, written by different mechanisms, and destroyed by different mechanisms.
Getting that distinction wrong in a recovery produces a file that looks complete and is not, and it usually happens at the exact moment when the data matters most.
Two spaces, two access paths
The flash array is read through the program counter during execution and through a pointer pair for constant data. The EEPROM is read through three registers: an address register pair, a data register, and a control register whose bits start an operation and report when it has finished.
| property | flash | EEPROM |
|---|---|---|
| size on this part | 128 KB | 4 KB |
| address space | program, word-addressed | data, byte-addressed |
| write unit | page | byte, with an internal erase-write cycle |
| write time | milliseconds per page | milliseconds per byte |
| endurance | tens of thousands of cycles | hundreds of thousands of cycles |
| erase as the unit | yes | no, the write includes the erase |
The last row explains why the EEPROM is the better place for a serial number. A flash page rewrite destroys the whole page; an EEPROM write touches one byte. A design that stores a counter and increments it once per hour would destroy a flash page in weeks and never wear out the EEPROM.
The write cycle is slow, and the code knows it
An EEPROM write takes milliseconds, which is an eternity for a 16 MHz core — tens of thousands of instruction cycles. Firmware cannot proceed to the next write until the current one completes, so every design contains a polling loop waiting on the busy flag, or an interrupt driven from the ready condition.
That polling loop is one of the more reliable landmarks in an unfamiliar image. It is tight, it reads the control register, it branches back to itself, and it appears wherever persistent data is written. Finding it locates the data-writing routines, and those routines are the ones that define the data layout.
The interrupt-driven variant is worth distinguishing. A design that enables the ready interrupt and writes from the service routine is one that decided the main loop could not afford the wait, which usually means the EEPROM is written from a state machine that also does something time-sensitive. That in turn suggests the data is being logged rather than configured.
Three reasons a byte reads as 0xFF
Erased is 0xFF. That single fact produces a class of misreading that is expensive because it looks like an answer.
A byte of 0xFF can mean the location has never been written since the part was manufactured, because the factory state is the erased state. It can mean the location was erased as part of a whole-device operation. And it can mean a write was interrupted, or a write failed, leaving the location in the erased state rather than holding either the old or the new value.
| reading | most likely cause | how to confirm |
|---|---|---|
| a block of 0xFF in an otherwise populated region | deliberate erase, or a write that never happened | check the surrounding record structure for a sequence gap |
| 0xFF at the very end of the array | never used | nothing to confirm; it is the expected state |
| scattered 0xFF inside a record | failed write | the record’s own checksum will disagree |
| the whole array 0xFF | erased device, or a read that returned nothing | read a known-non-blank location, or read the fuse bytes |
Distinguishing these requires structure, not more reading. If the data has records with sequence numbers or checksums, a gap and a checksum failure separate the cases immediately. If the data is a bare parameter block with no structure, the distinction may be unresolvable from the contents alone, and saying so is better than guessing.
What 4 KB actually holds
The size is large enough that the contents are not a handful of settings. On a part with this much EEPROM the array usually contains one of three things, and they read very differently:
- A parameter set with a header, a version byte and a checksum. Compact, often under a hundred bytes, and the rest of the array is erased.
- A rolling log. Records of fixed length walking through the array, each with an increasing sequence number or a timestamp, overwriting the oldest when the end is reached. The newest record is the answer a customer usually wants, and finding it means ordering by sequence rather than by address.
- A calibration table indexed by sensor or channel. Nearly full, with regularity across the array and values that vary smoothly between neighbouring entries.
The three are distinguishable at a glance in a hex dump, and telling the customer which one they have is often more useful than the dump itself, because it tells them what the device was doing.
Delivering it without merging it
The EEPROM contents belong in their own file. Merging them into the flash image destroys the address-space distinction and produces a file that no programmer can use correctly, since the two regions would be written to the same device through different mechanisms at different addresses.
The deliverable is therefore the flash image, a separate EEPROM image with its base address stated, the fuse and lock state as read, and a note describing the structure found in the EEPROM: header, record length, sequence field, checksum.
Where the design also keeps data in the flash array as constants, ATmega1280V program recovery covers the addressing that makes those reachable. The same three-way 0xFF ambiguity applied to a smaller data page is in ATtiny85V software recovery, and the erase interaction with protection in ATmega1280 flash recovery.
FAQ
Can the EEPROM be read while the flash is locked? Often yes, because the lock bits govern the flash array. The EEPROM has its own protection bit and it is frequently left unset.
Is the EEPROM erased by a chip erase? It depends on a fuse bit that decides whether the EEPROM is preserved through the erase. Read that bit before running one.
Why is the write so slow? The internal cycle performs an erase and a write per byte. The time is the physics of the floating gate, not a firmware inefficiency.
Conclusion
Treating a 4 KB EEPROM as a tail of the flash array produces a merged file that is useless and a data structure that is misread. Separated, it is the part of the device most likely to hold something irreplaceable: a serial number, a calibration, a log of what the unit did before it failed. Read it through its own registers, deliver it as its own file, and describe its structure in words.