I have an LCD display with touch controller which is under managed_components. The touch driver uses I2C communication.
I need also connect multiple I2C devices in my code, so i use the same logic for all the components:
FRAM:
Code: Select all
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = I2C_NUM_1,
.scl_io_num = CONFIG_I2C_FRAM_SCL_PIN,
.sda_io_num = CONFIG_I2C_FRAM_SDA_PIN,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
i2c_master_bus_handle_t bus_handle;
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = CONFIG_I2C_FRAM_ADDRESS,
.scl_speed_hz = 400000,
};
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &s_hMemory));
Code: Select all
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = I2C_NUM_1,
.scl_io_num = CONFIG_I2C_HOME_SENSORS_SCL_PIN,
.sda_io_num = CONFIG_I2C_HOME_SENSORS_SDA_PIN,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
i2c_master_bus_handle_t bus_handle;
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = CONFIG_I2C_HOME_SENSORS_ADDRESS,
.scl_speed_hz = 100000,
};
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &s_hSensors));
Code: Select all
E (3253) i2c.common: I2C bus id(1) has already been acquired
E (3253) i2c.common: acquire bus failed
E (3263) i2c.master: i2c_new_master_bus(804): I2C bus acquire failed
E (3263) i2c.common: i2c_release_bus_handle(154): Bus not freed entirely
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x400d9130