(answered) error checking i2c_cmd_link_create()?

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

(answered) error checking i2c_cmd_link_create()?

Postby mzimmers » Thu Feb 21, 2019 7:18 pm

Hi -

My app is occasionally experiencing GMEs. The backtrace suggests the problem is in my use of the I2C system. Is there a way to tell whether the call to i2c_cmd_link_create() is successful? I didn't see anything in the docs about this.

Thanks...

Code: Select all

    m_i2c_cmd = i2c_cmd_link_create();
    //ESP_LOGI(TAG, "i2cReadReg(): m_i2c_cmd is %x.", (unsigned) m_i2c_cmd);
    rc = (i2c_master_start(m_i2c_cmd));
    rc |= (i2c_master_write_byte(m_i2c_cmd, addrWrite, true));
    rc |= (i2c_master_write_byte(m_i2c_cmd, regAddr, true));
    rc |= (i2c_master_start(m_i2c_cmd));
    rc |= (i2c_master_write_byte(m_i2c_cmd, addrRead, true));
    rc |= (i2c_master_read(m_i2c_cmd, (uint8_t *) data, len, I2C_MASTER_LAST_NACK));
    rc |= (i2c_master_stop(m_i2c_cmd));
    rc |= (i2c_master_cmd_begin(I2C_PORT_NBR, m_i2c_cmd, I2C_WAITTIME_TICKS));
    if (rc == ESP_OK)
    {
        //ESP_LOGI(TAG, "readReg(): device address 0x%02x, register 0x%02x data read as 0x%x.", devAddr, regAddr, *data);
    }
    else
    {
        ESP_LOGE(TAG, "readReg(): error \"%s\" on device 0x%x, register 0x%x.",
                 esp_err_to_name(rc),
                 devAddr,
                 regAddr);
    }
    i2c_cmd_link_delete(m_i2c_cmd);
Last edited by mzimmers on Fri Feb 22, 2019 3:40 pm, edited 1 time in total.

ESP_Sprite
Posts: 9729
Joined: Thu Nov 26, 2015 4:08 am

Re: error checking i2c_cmd_link_create()?

Postby ESP_Sprite » Fri Feb 22, 2019 3:01 am

You should be able to see if the result equals NULL. If it is, you're out of memory. Aside from that, nothing can go wrong with that function.

User avatar
mzimmers
Posts: 643
Joined: Wed Mar 07, 2018 11:54 pm
Location: USA

Re: (answered) error checking i2c_cmd_link_create()?

Postby mzimmers » Fri Feb 22, 2019 3:40 pm

Thanks, Sprite.

Who is online

Users browsing this forum: No registered users and 78 guests