General Steps

[中文]

Note

This document is automatically translated using AI. Please excuse any detailed errors. The official English version is still in progress.

This document summarizes the general implementation process of the I2C peripheral in ESP-IDF, covering key peripheral configurations, initialization, and common operations, providing a unified implementation reference for different examples.

Mastering the content of this document helps to quickly understand the core usage process of the I2C peripheral, facilitating the reuse of common code in different applications.

I2C Initialization

The initialization of the I2C peripheral involves the configuration and initialization of the I2C bus and slave devices. For related instructions, please refer to Install I2C Master Bus and Devices.

Create/Initialize I2C Bus

  1. Create a bus handle variable of type i2c_master_bus_handle_t.

  2. Configure the I2C bus through the i2c_master_bus_config_t structure. For a description of the structure members, refer to I2C Interface.

  3. Call i2c_new_master_bus() to create an I2C bus based on the configuration and save the bus handle. For further introduction and parameter description, refer to I2C Interface.

Configure/Initialize I2C Slave Device

  1. Create a slave device handle variable of type i2c_master_dev_handle_t.

  2. Configure the I2C slave device through the i2c_device_config_t structure. For a description of the structure members, refer to I2C Interface.

  3. Call i2c_master_bus_add_device() to initialize the I2C slave device based on the configuration and save the device handle. For further introduction and parameter description, refer to I2C Interface.