ATTIny2313-16MI ATMEL Corporation, ATTIny2313-16MI Datasheet - Page 19

no-image

ATTIny2313-16MI

Manufacturer Part Number
ATTIny2313-16MI
Description
8-bit AVR Microcontroller with 2K Bytes In-System Programmable Flash
Manufacturer
ATMEL Corporation
Datasheet
Erase
Write
2543C–AVR–12/03
To erase a byte, the address must be written to EEAR. If the EEPMn bits are 0b01, writ-
ing the EEPE (within four cycles after EEMPE is written) will trigger the erase operation
only (programming time is given in Table 1). The EEPE bit remains set until the erase
operation completes. While the device is busy programming, it is not possible to do any
other EEPROM operations.
To write a location, the user must write the address into EEAR and the data into EEDR.
If the EEPMn bits are 0b10, writing the EEPE (within four cycles after EEMPE is written)
will trigger the write operation only (programming time is given in Table 1). The EEPE bit
remains set until the write operation completes. If the location to be written has not been
erased before write, the data that is stored must be considered as lost. While the device
is busy with programming, it is not possible to do any other EEPROM operations.
The calibrated Oscillator is used to time the EEPROM accesses. Make sure the Oscilla-
tor frequency is within the requirements described in “Oscillator Calibration Register –
OSCCAL” on page 26.
The following code examples show one assembly and one C function for writing to the
EEPROM. The examples assume that interrupts are controlled (e.g. by disabling inter-
rupts globally) so that no interrupts will occur during execution of these functions.
Assembly Code Example
C Code Example
EEPROM_write:
void EEPROM_write(unsigned int uiAddress, unsigned char ucData)
{
}
; Wait for completion of previous write
sbic EECR,EEWE
rjmp EEPROM_write
; Set up address (r17) in address register
out
; Write data (r16) to data register
out
; Write logical one to EEMWE
sbi
; Start eeprom write by setting EEWE
sbi
ret
/* Wait for completion of previous write */
while(EECR & (1<<EEWE))
/* Set up address and data registers */
EEAR = uiAddress;
EEDR = ucData;
/* Write logical one to EEMWE */
EECR |= (1<<EEMWE);
/* Start eeprom write by setting EEWE */
EECR |= (1<<EEWE);
;
EEAR, r17
EEDR,r16
EECR,EEMWE
EECR,EEWE
ATtiny2313/V
19

Related parts for ATTIny2313-16MI