
21
ATmega8515(L)
2512A–AVR–04/02
Thenext codeexamplesshow assembly andCfunctionsforreading the EEPROM.The
examples assume that interrupts are controlledsothat no interruptswill occurduring
execution of these functions.
Preventing EEPROM
Corruption
During periods oflow V
CC
, the EEPROM data can be corruptedbecausethe supply volt-
age is too lowfor the CPU and the EEPROM to operate properly.Theseissues arethe
same asforboard levelsystems using EEPROM, and the same design solutionsshould
beapplied.
An EEPROM data corruption can be causedbytwo situationswhen thevoltage is too
low. First, a regularwrite sequencetothe EEPROM requires aminimumvoltage to
operate correctly. Secondly, the CPU itself can execute instructions incorrectly, if the
supply voltage is too low.
EEPROM data c orruption can easily beavoidedbyfollowing th isdesign
recommendation:
Keep the AVR RESETactive (low) during periods of insufficient powersupply volt-
age. Thiscan be done by enabling theinternalBrown-out Detector(BOD). If the
detection level of theinternalBODdoes not match theneededdetection level, an
externallow V
CC
Reset Protection circuit can beused. If aReset occurs whilea
write operation is in progress, the write operation will be completedprovided that the
powersupply voltage issufficient.
Assembly Code Example
EEPROM_read:
; Wait for completion of previous write
sbic EECR,EEWE
rjmp EEPROM_read
; Set up address (r18:r17) in address register
out EEARH, r18
out EEARL, r17
; Start eeprom read by writing EERE
sbi EECR,EERE
; Read data from data register
in r16,EEDR
ret
CCode Example
unsigned char EEPROM_read(unsigned int uiAddress)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEWE))
;
/* Set up address register */
EEAR = uiAddress;
/*
Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
}
Comentários a estes Manuais