I tried out the IDF 5.2 branch as to the new I2C driver implementation. Unfortunately, I cant get it to work to read data from devices in master mode. Writing data to devices works like a charm.
Using reading functions (i2c_master_receive or i2c_master_transmit_receive) leads to a hang and a watchdog timeout in ISR.
After fail and restart, the I2C is left in an unusable state. Thus, calling i2c_new_master_bus leads to a hang and WDT timeout as well, unfortunately.
Please, could you investigate?
Here is my code snippet in order to communicate with a BME280 device:
Code: Select all
i2c_master_bus_config_t conf = {
.i2c_port = -1,
.sda_io_num = GPIO_NUM_21,
.scl_io_num = GPIO_NUM_22,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7,
};
ESP_LOGI(LOGTAG, "MasterInit call new master bus");
i2c_master_bus_handle_t handle = NULL;
esp_err_t err = i2c_new_master_bus(&conf, &handle);
if (err != ESP_OK)
{
ESP_LOGE(LOGTAG, "i2c new master failed:%d", err);
}
if (i2c_master_probe(handle, 0x76, 10) == ESP_OK)
{
ESP_LOGI(LOGTAG, "found device at $%02x", 0x76);
i2c_master_dev_handle_t hDev = NULL;
i2c_device_config_t cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = 0x76,
.scl_speed_hz = 100000,
};
err = i2c_master_bus_add_device(handle, &cfg, &hDev);
if (err == ESP_OK)
{
ESP_LOGI(LOGTAG, "read chip revision of BM*280");
uint8_t reg = 208;
uint8_t data = 0;
err = i2c_master_transmit_receive(hDev, ®, 1, &data, 1, -1);
ESP_LOGI(LOGTAG, "transmit/receive: %d", err);
if (err == ESP_OK)
ESP_LOGI(LOGTAG, "Chip ID=%02x", data);
else
ESP_LOGE(LOGTAG, "failed %d", err);
}
// freigeben
i2c_master_bus_rm_device(hDev);
}
Christoph