<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[i2c read timeout issue while reading Pb hub through atom lite in ESP-IDF]]></title><description><![CDATA[<p dir="auto">hey there, i am using ESP-IDF to program the atom lite, i have a Pb hub and i want to configure it with atom lite using the espidf, but the issue is i am getting read timeout error (error code 0x107) below is the code i am using.</p>
<p dir="auto">#include &lt;stdio.h&gt;<br />
#include "esp_log.h"<br />
#include "driver/i2c.h"</p>
<p dir="auto">static const char *TAG = "i2c-simple-example";</p>
<p dir="auto">#define I2C_MASTER_SCL_IO 32        /*!&lt; GPIO number used for I2C master clock <em>/<br />
#define I2C_MASTER_SDA_IO 26        /</em>!&lt; GPIO number used for I2C master data  <em>/<br />
#define I2C_MASTER_NUM 0            /</em>!&lt; I2C master i2c port number, the number of i2c peripheral interfaces available will depend on the chip <em>/<br />
#define I2C_MASTER_FREQ_HZ 400000   /</em>!&lt; I2C master clock frequency <em>/<br />
#define I2C_MASTER_TX_BUF_DISABLE 0 /</em>!&lt; I2C master doesn't need buffer <em>/<br />
#define I2C_MASTER_RX_BUF_DISABLE 0 /</em>!&lt; I2C master doesn't need buffer */<br />
#define I2C_MASTER_TIMEOUT_MS 1000</p>
<p dir="auto">#define MPU9250_SENSOR_ADDR 0x61       /*!&lt; Slave address of the MPU9250 sensor <em>/<br />
#define MPU9250_WHO_AM_I_REG_ADDR 0x61 /</em>!&lt; Register addresses of the "who am I" register */</p>
<p dir="auto">#define MPU9250_PWR_MGMT_1_REG_ADDR 0x6B /*!&lt; Register addresses of the power managment register */<br />
#define MPU9250_RESET_BIT 7</p>
<p dir="auto">/**</p>
<ul>
<li>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/brief" aria-label="Profile: brief">@<bdi>brief</bdi></a> Read a sequence of bytes from a MPU9250 sensor registers<br />
*/<br />
static esp_err_t mpu9250_register_read(uint8_t reg_addr, uint8_t *data, size_t len)<br />
{<br />
esp_err_t err = ESP_OK;<br />
err = i2c_master_write_read_device(I2C_NUM_0, MPU9250_SENSOR_ADDR, &amp;reg_addr, 1, data, len, I2C_MASTER_TIMEOUT_MS / portTICK_RATE_MS);<br />
return err;<br />
}<br />
static esp_err_t i2c_master_init(void)<br />
{<br />
i2c_config_t conf = {<br />
.mode = I2C_MODE_MASTER,<br />
.sda_io_num = I2C_MASTER_SDA_IO,<br />
.scl_io_num = I2C_MASTER_SCL_IO,<br />
.sda_pullup_en = GPIO_PULLUP_ENABLE,<br />
.scl_pullup_en = GPIO_PULLUP_ENABLE,<br />
.master.clk_speed = I2C_MASTER_FREQ_HZ,<br />
};</p>
<p dir="auto">i2c_param_config(I2C_NUM_0, &amp;conf);<br />
i2c_set_timeout(I2C_NUM_0, 400000);<br />
return i2c_driver_install(I2C_NUM_0, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);<br />
}</p>
</li>
</ul>
<p dir="auto">void app_main(void)<br />
{<br />
uint8_t data[2];<br />
ESP_ERROR_CHECK(i2c_master_init());<br />
ESP_LOGI(TAG, "I2C initialized successfully");</p>
<pre><code>while (1)
{
    esp_err_t err = mpu9250_register_read(0x00, data, 1);
    if (err != ESP_OK)
    {
        int timevalue;
        i2c_get_timeout(I2C_NUM_0, &amp;timevalue);
        ESP_LOGI(TAG, "time value is : %d  err[%d]", timevalue, err);
    }
    ESP_LOGI(TAG, "WHO_AM_I = %X", data[0]);
    vTaskDelay(2000 / portTICK_PERIOD_MS);
}

ESP_ERROR_CHECK(i2c_driver_delete(I2C_NUM_0));
ESP_LOGI(TAG, "I2C unitialized successfully");
</code></pre>
<p dir="auto">}</p>
<p dir="auto">Note : interestingly i am able to read and write the Pb hub using the arduino ide wire library so i am confused what could be the issue.<br />
i have go through all the documentation and help i could get online to resolve the issue but i am unable to solve it. any help in this regard would be highly appreciated.</p>
]]></description><link>https://community.m5stack.com/topic/6443/i2c-read-timeout-issue-while-reading-pb-hub-through-atom-lite-in-esp-idf</link><generator>RSS for Node</generator><lastBuildDate>Tue, 28 Apr 2026 21:19:01 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6443.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 May 2024 08:50:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to i2c read timeout issue while reading Pb hub through atom lite in ESP-IDF on Sun, 12 May 2024 02:45:17 GMT]]></title><description><![CDATA[<p dir="auto">can you try adding  ESP_ERROR_CHECK(esp_event_loop_create_default()); and see what errors you get?</p>
<p dir="auto">When I compile and deploy my project, I see the following warning</p>
<p dir="auto">i2c: This driver is an old driver; please migrate your application code to adapt <code>driver/i2c_master.h</code>,</p>
<p dir="auto">which causes my system to never finish initialization. In my case, the M5Unified library needs to be updated to use driver/i2c_master.h</p>
<p dir="auto">Perhaps your timeout is related to the loop never initializing. At this point, I am only guessing what the issue might be.</p>
]]></description><link>https://community.m5stack.com/post/25191</link><guid isPermaLink="true">https://community.m5stack.com/post/25191</guid><dc:creator><![CDATA[that_design_student]]></dc:creator><pubDate>Sun, 12 May 2024 02:45:17 GMT</pubDate></item></channel></rss>