The 24C02 slave address setting in I2C distinguishes the device address and the register address

24C02 slave address setting in I2C

Slave address

    First, take a look at the chip information of AT24C02, we will find that AT24C02 has three addresses A0, A1, A2. At the same time, we will find that I2C devices have a total of seven address codes in the Device Address introduction of the data , and one is the read/write (R/W) operation bit, and the first four bits of AT24C02 have been fixed to 1010. If R/W is 1, it is a read operation, and if it is 0, it is a write operation. We want to set the R/W bit to 0 (write operation)

The rule is: 1010 (A0) (A1) (A2) (R/W)

    Then, take a look at the connection of the three-bit address pin of the AT24C02 on the setup PCB of your own.

Example 1:

Then the corresponding A0, A1, and A2 are all connected to VCC, so A0=1, A1=1, A2=1; you can know that the write address of the slave device of AT24C02 is 10101110 (0xae), and the read device address is 10101111 (0xaf) ;

 

 

Example 2:

Then the corresponding A0, A1, and A2 are all connected to GND, so A0=0, A1=0, A2=0; you can know that the write address of the AT24C02 slave device is 10100000 (0xa0), and the read device address is 10100001 (0xa1) ;

Haha, the " Slave Device Address" is so determined, it's actually very simple.

 

Reference http://blog.chinaunix.net/uid-29727172-id-5573269.html

Reprinted at: https://www.cnblogs.com/caolinsummer/p/5660863.html

 

-------------------------------------------------------------------------------------------

EEPROM should be the first thing to contact when learning IIC bus. The advantage of EEPROM is that it can be accessed randomly. Unlike Flash memory, it needs to be erased before it can be written, and the number of erasing and writing times is long and the storage time is long, but the disadvantage is storage. The space is very limited. For example, the Atmel AT24C08 that I use has only 8Kbit storage space, that is, only 1KB. It is enough to store some parameters, but it doesn’t matter if you store documents, audio, etc. Fortunately, I only need to store some parameters in my current project. The space of AT24C02 is not enough, so AT24C08 which has a larger space is used.

I thought the two programs were similar, but there are still some noteworthy points that need to be recorded.


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 , it is enough to send one byte of register address directly , but the storage space of AT24C08 is 1024Byte, one The byte register address is not enough for addressing, and a 10-bit addressing space is required.

I wrote an article before: http://blog.csdn.net/tq384998430/article/details/53580267

IIC reads and writes registers with 16-bit addresses


Generally speaking, the internal register addresses of IIC devices are all 8 bits, so when reading and writing operations, after sending the device address, send a byte of the register address directly, and then you can read and write.

However, the internal registers of some devices are arranged according to 16-bit addresses. For example, some EEPROM devices require a larger addressing space due to the large amount of stored data. For such devices, multiple internal register addresses are required. Byte address, that is, after sending the device address , multiple register address bytes need to be sent ,

The specific implementation is shown in the following program:

u8 IIC_Read2(u8 device,u16 addr)
{     u8 temp;     IIC_Start();     IIC_SendByte(device);     IIC_Wait_Ack();     IIC_SendByte((u8)(addr >> 8));     IIC_Wait_Ack();     IIC_SendByte((u8)addr) ;     IIC_Wait_Ack();     IIC_Start();     IIC_SendByte(device+1);     IIC_Wait_Ack();     temp = IIC_ReadByte();     IIC_NAck();//Send nACK     IIC_Stop();     return temp; } The device can be seen through the program After the address device, the high byte and low byte of the register address are sent successively, and then read.

















 

It explains the way IIC reads and writes 16-bit address registers, which is to send two bytes of register address , first send the high byte of the address, and then send the low byte of the address, but this trick is not applicable on AT24C08

Then I was forced to look at the AT24C08 data sheet http://pdf1.alldatasheet.com/datasheet-pdf/view/509421/ATMEL/AT24C08C-SSHM-T.html, the above page 10 wrote:


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.


The device address of AT24C08 is defined as follows:

Write picture description here

To put it very clearly, AT24C08 regards 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 must The highest two digits 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(); } ———————————————— Copyright statement: This article is the original article of the CSDN blogger "Mr qqtang", following the CC 4.0 BY-SA copyright agreement, Please attach a link to the original source and this statement for reprinting. Original link: https://blog.csdn.net/tq384998430/article/details/79227271











Guess you like

Origin blog.csdn.net/chenhuanqiangnihao/article/details/114997299