I2C Read and Write EEPROM—Introduction to EEPROM

      EEPROM is a memory that does not lose data after power failure. It is often used to store some configuration information so that it can be loaded when the system is powered on again. The most commonly used communication method for EEPOM chips is the I 2C protocol. This section uses the EEPROM reading and writing experiments to explain how to use the STM32 software to simulate the I 2C protocol for communication.

1

3

     The SCL and SDA pins of the EEPROM chip (model: AT24C02) in this experiment board are connected to the ordinary GPIO pins of STM32, combined with pull-up resistors to form an I2C communication bus, and they interact through the I2C bus.

    The device address of the EEPROM chip has a total of 7 bits, of which the upper 4 bits are fixed as: 1010 b, and the lower 3 bits are determined by the level of the A0/A1/A2 signal line, as shown in Figure 24-10, R/W in the figure is The read and write direction bits are independent of the address.

 2

     According to our connection here, A0/A1/A2 are all 0, so the 7-bit device address of the EEPROM is: 101 0000b, that is, 0x50. Because the address and the read and write direction are often connected together to form an 8-digit number in I2C communication, and when the R/W bit is 0, it indicates the write direction, so add a 7-bit address, and its value is "0xA0", often called This value is the "write address" of the I2C device; when the R/W bit is 1, it indicates the read direction, plus the 7-bit address, the value is "0xA1", which is often called the "read address". There is also a WP pin in the EEPROM chip, which has a write protection function. When the pin is high, data writing is prohibited. When the pin is low, data can be written. We directly connect to ground and do not use writing. Protective function. For more information about EEPROM, please refer to its data sheet "AT24C02". If the model, device address or control pins of the experimental board EEPROM you use are different, you only need to modify it according to our project, and the control principle of the program is the same.

Guess you like

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