I2C timeout
Posted: Fri Aug 09, 2019 3:19 pm
Hi,
I have an ESP32 WROVER dev board and a BQ27220. I am trying to read its device number.
I have a logic analyzer to monitor the traffic as well.
This is the code that I am using:
The problem is that the read command returns 107 (timeout error). The logic analyzer shows that there is not response from BQ27220 after starting the reading.
To double check that BQ27220 is find, I got this library (https://github.com/sparkfun/SparkFun_BQ ... no_Library). It is for another IC, but the device number request sequence is the same. I tested it with an Arduino and it was working.
Also, I compiled this example for Arduino-ESP32 and uploaded it to my board and it worked.
This makes me think that there is a problem with ESP-IDF, but I cannot understand what is wrong.
How should I debug further?
I have an ESP32 WROVER dev board and a BQ27220. I am trying to read its device number.
I have a logic analyzer to monitor the traffic as well.
This is the code that I am using:
Code: Select all
esp_err_t ret;
i2c_cmd_handle_t cmd;
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i2c_addr << 1) | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, 0x00, true);
i2c_master_write_byte(cmd, 0x01, true);
i2c_master_write_byte(cmd, 0x00, true);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
DELAY(1000);
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i2c_addr << 1) | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, 0x40, true);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
DELAY(2000);
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (i2c_addr << 1) | I2C_MASTER_READ, true);
i2c_master_read(cmd, data, data_len, I2C_MASTER_LAST_NACK);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 5000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
To double check that BQ27220 is find, I got this library (https://github.com/sparkfun/SparkFun_BQ ... no_Library). It is for another IC, but the device number request sequence is the same. I tested it with an Arduino and it was working.
Also, I compiled this example for Arduino-ESP32 and uploaded it to my board and it worked.
This makes me think that there is a problem with ESP-IDF, but I cannot understand what is wrong.
How should I debug further?