4.4.5.1 Eeprom Variables

Objects can be placed in the EEPROM by specifying that they be placed in the .eeprom section, using the section attribute. A warning is produced if the attribute is not supported for the selected device. Check your device data sheet to see the memory available with your device.

The macro EEMEM is defined in <avr/eeprom.h> and can be alternatively used to simplify the definition of objects in EEPROM. For example, both the following definitions create objects which will be stored in EEPROM.

int serial __attribute__((section(.eeprom)));
char EEMEM ID[5] = { 1, 2, 3, 4, 5 };

Objects in this section are cleared or initialized, as required, just like ordinary RAM-based objects; however, the initialization process is not carried out by the runtime startup code. Initial values are placed into a HEX file and are burnt into the EEPROM when you program the device. If you modify the EEPROM during program execution and then reset the device, these objects will not contain the initial values specified in your code at startup up.

Note that the objects that are in the eeprom section must all use the const type qualifier or all not use this qualifier.