Operation of EEPROM AT24C08

EEPROM should be the first thing to contact when learning the IIC bus. The advantage of EEPROM is that it can be accessed randomly. Unlike Flash memory, it needs to be erased first before it can be written, and the number of times of erasing and writing is long. The storage time is long, but the disadvantage is that the storage The space is very limited. For example, the Atmel AT24C08 I use has only 8Kbit storage space, that is, only 1KB. It is enough to store some parameters, but it is enough to store documents and audio. Fortunately, I only need to store some parameters in my current project. The space of AT24C02 is not enough, so the AT24C08 with a relatively larger space is used. I thought that the two programs are similar, but there are some noteworthy places to record.
Since the storage space of AT24C02 is 256Byte, one byte is enough when IIC sends the addressing address, that is, after sending the device address, one byte of register address can be sent directly, but the storage space of AT24C08 is 1024Byte, a The byte address is not enough for addressing, and requires 10-bit addressing space. I wrote an article before: http://blog.csdn.net/tq384998430/article/details/53580267 It explains that IIC reads and writes 16-bit addresses The way to use the register is to send the register address of two bytes, first send the high byte of the address, and then send the low byte of the address, but this trick is not applicable to AT24C08, and then forced me to look at the data of AT24C08 The manual http://pdf1.alldatasheet.com/datasheet-pdf/view/509421/ATMEL/AT24C08C-SSHM-T.html , page 10 above says:
Standard EEPROM Access: The 4K and 8K EEPROM device requires an 8- bit device address word following a start
condition to enable the chip for a read or write operation. The device address word consists of a mandatory “1010” (0xA)
sequence for the first four Most Significant Bits (MSB) as shown in Figure 8-1 on page 11. This is common to all the
EEPROM devices.
The 4K EEPROM only uses the A2 and A1 device address bits with the third bit being a memory page address bit. The
two device address bits must compare to their corresponding hard-wired input pins. The A0 pin is no connect.
The 8K EEPROM only uses the A2 device address bit with the next two bits being for memory page addressing. The A2
address bit must compare to its corresponding hard-wired input pin. The A1 and A0 pins are no connect.
AT24C08的器件地址的定义如下:
write picture description here
It is very clear that AT24C08 uses the A1 and A0 bits in the device address (Device Addr) as the Page address, which means that A1 and A0 are the highest two bits in the 10-bit address of the memory. When we read and write data, we need to The top two bits of the address (page address) are placed here. The sample program is as follows:

void IIC_Send(u8 device,u16 addr,u8 dat)
{
    IIC_Start();
    IIC_SendByte(device | (addr >> 8));
    IIC_Wait_Ack();
    IIC_SendByte((u8)addr);  
    IIC_Wait_Ack();  
    IIC_SendByte(dat);
    IIC_Wait_Ack();
    IIC_Stop();
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325601449&siteId=291194637