i2c能正确读到数据,但是仍然会返回ESP_ERR_TIMEOUT

Weizzh
Posts: 19
Joined: Mon Nov 22, 2021 9:32 am

i2c能正确读到数据,但是仍然会返回ESP_ERR_TIMEOUT

Postby Weizzh » Thu Jan 13, 2022 3:00 am

ESP-IDF v4.2-dev-1304-gaeff546-dirty ,芯片是ESP32 WROOM-32U
如标题描述,可以通过i2c读到数据,但是i2c_master_cmd_begin()函数会返回ESP_ERR_TIMEOUT问题,其中等待时间不管改成多大都没有用。

Code: Select all

    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (slave_device_address<<1)|I2C_MASTER_WRITE, ACK_CHECK_EN );
    i2c_master_write_byte(cmd, read_address, ACK_CHECK_EN);
    i2c_master_start(cmd);
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (slave_device_address<<1)|I2C_MASTER_READ, ACK_CHECK_EN);
    i2c_master_read(cmd, data_rd, data_length, I2C_MASTER_ACK);
    i2c_master_stop(cmd);
    esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 1000/portTICK_RATE_MS);
    i2c_cmd_link_delete(cmd);
    return ret;

Lvista
Posts: 3
Joined: Mon Dec 18, 2023 12:10 pm

Re: i2c能正确读到数据,但是仍然会返回ESP_ERR_TIMEOUT

Postby Lvista » Tue Dec 19, 2023 3:17 am

我也遇到这个问题,总是时不时地出现超时错误

ESP_MacChu
Posts: 47
Joined: Tue Nov 21, 2023 7:53 am

Re: i2c能正确读到数据,但是仍然会返回ESP_ERR_TIMEOUT

Postby ESP_MacChu » Thu Dec 21, 2023 7:28 am

返回 ESP_ERR_TIMEOUT 但能正常读数据意味着总线正忙

axellin
Posts: 199
Joined: Mon Sep 17, 2018 9:09 am

Re: i2c能正确读到数据,但是仍然会返回ESP_ERR_TIMEOUT

Postby axellin » Thu Dec 21, 2023 8:14 am

ESP_MacChu wrote:
Thu Dec 21, 2023 7:28 am
返回 ESP_ERR_TIMEOUT 但能正常读数据意味着总线正忙
But this looks strange.
If it returns ESP_ERR_TIMEOUT, is the reading correct?

ESP_MacChu
Posts: 47
Joined: Tue Nov 21, 2023 7:53 am

Re: i2c能正确读到数据,但是仍然会返回ESP_ERR_TIMEOUT

Postby ESP_MacChu » Mon Jan 08, 2024 6:07 am

当返回ESP_OK时,数据是正确的。但是当返回ESP_ERR_TIMEOUT时,数据是不可用的。
为了处理这种情况可以:1. 延长等待时间 2. 应用层判断超时后进行重发

Who is online

Users browsing this forum: No registered users and 154 guests