(solved) I2C device poses a challenge
-
- Posts: 47
- Joined: Thu Dec 20, 2018 9:47 am
Re: I2C device poses a challenge
Hmm..., what's the value of I2C_WAITTIME_TICKS?
Re: I2C device poses a challenge
Currently it's 500. I've tried all sorts of values (beginning with 5); no change in results.
Evidently someone else had this problem about a year ago:
viewtopic.php?t=1226
Still trying to make sense of it.
ADDED: I just put a call to i2c_get_timeout in my read -- came back as 640. As the units are APB 80Mhz clock cycle, that sounds like 8us. Doesn't seem like enough for this device, does it?
Evidently someone else had this problem about a year ago:
viewtopic.php?t=1226
Still trying to make sense of it.
ADDED: I just put a call to i2c_get_timeout in my read -- came back as 640. As the units are APB 80Mhz clock cycle, that sounds like 8us. Doesn't seem like enough for this device, does it?
Re: I2C device poses a challenge
I'm getting closer (I think)...here's my code:
And I get timeouts. Any suggestions? Thanks.
Code: Select all
m_i2c_cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_start(m_i2c_cmd));
ESP_ERROR_CHECK(i2c_master_write_byte(m_i2c_cmd, SHT20_ADDR_WRITE, true));
ESP_ERROR_CHECK(i2c_master_write_byte(m_i2c_cmd, cmd, true));
ESP_ERROR_CHECK(i2c_master_stop(m_i2c_cmd));
rc = (i2c_master_cmd_begin(I2C_PORT_NBR, m_i2c_cmd, I2C_WAITTIME_TICKS));
i2c_cmd_link_delete(m_i2c_cmd);
if (rc == ESP_OK)
{
ESP_LOGI(TAG, "thermRead(): command write successful.");
}
else
{
ESP_LOGE(TAG, "thermRead(): command write error \"%s\".", esp_err_to_name(rc));
}
// write the read address.
do
{
m_i2c_cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_start(m_i2c_cmd));
ESP_ERROR_CHECK(i2c_master_write_byte(m_i2c_cmd, SHT20_ADDR_READ, true));
ESP_ERROR_CHECK(i2c_master_read(m_i2c_cmd, data, 3, I2C_MASTER_ACK));
rc = (i2c_master_cmd_begin(I2C_PORT_NBR, m_i2c_cmd, I2C_WAITTIME_TICKS));
i2c_cmd_link_delete(m_i2c_cmd);
if (rc == ESP_OK)
{
ESP_LOGI(TAG, "thermRead(): send of read address successful.");
break;
}
else if (rc == ESP_FAIL)
{
ESP_LOGE(TAG, "thermRead(): read error; SHT20 didn't send an ACK");
m_i2c_cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_stop(m_i2c_cmd));
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_PORT_NBR, m_i2c_cmd, I2C_WAITTIME_TICKS));
i2c_cmd_link_delete(m_i2c_cmd);
}
else
{
ESP_LOGE(TAG, "thermRead(): send of read address error \"%s\".", esp_err_to_name(rc));
}
}
while (i++ < 10);
Re: I2C device poses a challenge
You are still using E3 instead of F3. A conversion can take up to 85ms, would your loop cover that amount of time?
Re: I2C device poses a challenge
Noted about F3. Thanks for that catch; I hadn't noticed that, and was wondering about how to choose a mode.
I set my timeout value to 6400 (units of 80MHz clock). I thought that would be enough for a single loop iteration, but maybe I dropped a digit in my mental calculation.
Because...
Strangely, it works on the last iteration for a variety of timeout settings: 6400, 10000, 20000. Any idea why this might be?
19C seems a little off, too. I'm going to put the sensor over a cup of coffee and re-test.
I set my timeout value to 6400 (units of 80MHz clock). I thought that would be enough for a single loop iteration, but maybe I dropped a digit in my mental calculation.
Because...
Works on the last iteration.I (205) Thermometer: i2cInit(): i2c_param_config() completed successfully.
I (205) Thermometer: i2cInit(): i2c_driver_install() completed successfully.
I (455) Thermometer: thermReset(): successful
I (465) Thermometer: thermRead(): timeout value is 6400.
I (465) Thermometer: thermRead(): command write successful.
E (465) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (465) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (475) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (485) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (495) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (495) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (505) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (515) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
E (515) Thermometer: thermRead(): read error; SHT20 didn't send an ACK
I (525) Thermometer: thermRead(): send of read address successful.
I (535) Thermometer: the temperature is 19.C.
Strangely, it works on the last iteration for a variety of timeout settings: 6400, 10000, 20000. Any idea why this might be?
19C seems a little off, too. I'm going to put the sensor over a cup of coffee and re-test.
Re: I2C device poses a challenge
20000 = 250 microseconds, max timeout would be 0xFFFFF = 13ms. However in no hold mode the device should be just nacking so you shouldn't be depending on that for your loop delay, use an actual delay.
Re: I2C device poses a challenge
Do you mean something like a call to vTaskDelay() between loop iterations?
Re: (solved) I2C device poses a challenge
Hi
I tried to read SHT20 registers with I2C tool with "i2cget" command, but it has error
"ESP_ERR_TIMEOUT Operation timeout because the bus is busy"
esp_err_t = 0x107
what does it mean?
Maybe it depends on the timout setting. (i2c_set_timeout)
I trid to set timeout in multi value but it doesn't work
Do you have sample cose?
would you please help me.
I tried to read SHT20 registers with I2C tool with "i2cget" command, but it has error
"ESP_ERR_TIMEOUT Operation timeout because the bus is busy"
esp_err_t = 0x107
what does it mean?
Maybe it depends on the timout setting. (i2c_set_timeout)
I trid to set timeout in multi value but it doesn't work
Do you have sample cose?
would you please help me.
Who is online
Users browsing this forum: No registered users and 94 guests