Datasheet
23
8246B–AVR–09/11
ATtiny2313A/4313
Note: See “Code Examples” on page 7.
5.4 Register Description
5.4.1 EEAR – EEPROM Address Register
• Bit 7 – EEAR7: EEPROM Address
This is the most significant EEPROM address bit of ATtiny4313. In devices with less EEPROM,
i.e. ATtiny2313A, this bit is reserved and will always read zero. The initial value of the EEPROM
Address Register (EEAR) is undefined and a proper value must therefore be written before the
EEPROM is accessed.
• Bits 6..0 – EEAR6..0: EEPROM Address
These are the (low) bits of the EEPROM Address Register. The EEPROM data bytes are
addressed linearly in the range 0...(128-1). The initial value of EEAR is undefined and a proper
value must be therefore be written before the EEPROM may be accessed.
5.4.2 EEDR – EEPROM Data Register
• Bits 7..0 – EEDR7..0: EEPROM Data
For the EEPROM write operation the EEDR Register contains the data to be written to the
EEPROM in the address given by the EEAR Register. For the EEPROM read operation, the
EEDR contains the data read out from the EEPROM at the address given by EEAR.
C Code Example
unsigned char EEPROM_read(unsigned int ucAddress)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE));
/* Set up address register */
EEAR = ucAddress;
/* Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
}
Bit 76543210
0x1E (0x3E) EEAR7 EEAR6 EEAR5 EEAR4 EEAR3 EEAR2 EEAR1 EEAR0 EEAR
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value X X X X X X X X
Bit 76543210
0x1D (0x3D) EEDR7 EEDR6 EEDR5 EEDR4 EEDR3 EEDR2 EEDR1 EEDR0 EEDR
Read/Write R/W R/W R/W R/W R/W R/W R/W R/W
Initial Value 0 0 0 0 0 0 0 0