# I2C - eeprom Source: [https://docs.qualcomm.com/doc/80-58740-4/topic/i2c-eeprom.html](https://docs.qualcomm.com/doc/80-58740-4/topic/i2c-eeprom.html) This demo mainly introduces I2C reading and writing eeprom. ## Hardware connection The GPIO used in this demo refers to `board_i2c0_gpio_init`. Connect the eeprom module to the development board. The specific pin connection method is as follows (taking QCC743 as an example): | I2C single | eeprom signal | | --- | --- | | SCL(GPIO14) | SCL | | SDA(GPIO15) | SDA | | GND | GND | | VCC | VCC | ## Software implementation For more detailed code, refer to examples/peripherals/i2c/i2c\_eeprom. board_init();Copy to clipboard - `board_init` turns on the I2C IP clock and select the I2C clock source and frequency division. board_i2c0_gpio_init();Copy to clipboard - Configure related pins as `I2C` function i2c0 = qcc74x_device_get_by_name("i2c0"); qcc74x_i2c_init(i2c0, 400000);Copy to clipboard - Get the `i2c0` handle and initialize the i2c0 frequency to 400K struct qcc74x_i2c_msg_s msgs[2]; uint8_t subaddr[2] = { 0x00, EEPROM_SELECT_PAGE0}; uint8_t write_data[256]; /* Write and read buffer init */ for (size_t i = 0; i < 256; i++) { write_data[i] = i; read_data[i] = 0; } /* Write page 0 */ msgs[0].addr = 0x50; msgs[0].flags = I2C_M_NOSTOP; msgs[0].buffer = subaddr; msgs[0].length = 2; msgs[1].addr = 0x50; msgs[1].flags = 0; msgs[1].buffer = write_data; msgs[1].length = EEPROM_TRANSFER_LENGTH; qcc74x_i2c_transfer(i2c0, msgs, 2);Copy to clipboard - Initialize sending data (write\_data), receiving buffer and configuring slave device information (msgs) - `qcc74x_i2c_transfer(i2c0, msgs, 2)` enables I2C transfer uint8_t read_data[256]; /* Read page 0 */ msgs[1].addr = 0x50; msgs[1].flags = I2C_M_READ; msgs[1].buffer = read_data; msgs[1].length = EEPROM_TRANSFER_LENGTH; qcc74x_i2c_transfer(i2c0, msgs, 2);Copy to clipboard - Read the data in the slave device register address and store it in read\_data - `qcc74x_i2c_transfer(i2c0, msgs, 2)` enables I2C transfer /* Check read data */ for (uint8_t i = 0; i < EEPROM_TRANSFER_LENGTH; i++) { if (write_data[i] != read_data[i]) { printf("check fail, %d write: %02x, read: %02x\r\n", i, write_data[i], read_data[i]); } }Copy to clipboard - Check whether the data sent and read are consistent ## Experimental phenomena Press the RST button and after the data transfer is completed, “write over”, “read over” and “check over” are printed. **Parent Topic:** [I2C](https://docs.qualcomm.com/doc/80-58740-4/topic/i2c.html) Last Published: Feb 10, 2025 [Previous Topic I2C - 10-bit](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/i2c-10-bit.md) [Next Topic I2C - eeprom\_dma](https://docs.qualcomm.com/bundle/publicresource/80-58740-4/topics/i2c-eeprom-dma.md)