Datasheet

21
ATtiny828 [DATASHEET]
8371A–AVR–08/12
At low supply voltages data in EEPROM can be corrupted in two ways:
z The supply voltage is too low to maintain proper operation of an otherwise legitimate EEPROM program
sequence.
z The supply voltage is too low for the CPU and instructions may be executed incorrectly.
EEPROM data corruption is avoided by keeping the device in reset during periods of insufficient power supply voltage.
This is easily done by enabling the internal Brown-Out Detector (BOD). If BOD detection levels are not sufficient for the
design, an external reset circuit for low V
CC
can be used.
Provided that supply voltage is sufficient, an EEPROM write operation will be completed even when a reset occurs.
5.3.6 Program Examples
The following code examples show one assembly and one C function for erase, write, or atomic write of the EEPROM.
The examples assume that interrupts are controlled (e.g., by disabling interrupts globally) so that no interrupts occur
during execution of these functions.
The examples also assume that a boot loader is not used. If a boot loader is present, the EEPROM write function must
be expanded to wait for any ongoing SPM operations to finish.
Note: See “Code Examples” on page 7.
Assembly Code Example
EEPROM_write:
sbic EECR, EEPE
rjmp EEPROM_write; Wait for completion of previous write
ldi r16, (0<<EEPM1)|(0<<EEPM0)
out EECR, r16 ; Set Programming mode
out EEARH, r18
out EEARL, r17 ; Set up address (r18:r17) in address registers
out EEDR, r19 ; Write data (r19) to data register
sbi EECR, EEMPE ; Write logical one to EEMPE
sbi EECR, EEPE ; Start eeprom write by setting EEPE
ret