Page 1 of 1

(answered) error checking i2c_cmd_link_create()?

Posted: Thu Feb 21, 2019 7:18 pm
by mzimmers
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);

Re: error checking i2c_cmd_link_create()?

Posted: Fri Feb 22, 2019 3:01 am
by ESP_Sprite
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.

Re: (answered) error checking i2c_cmd_link_create()?

Posted: Fri Feb 22, 2019 3:40 pm
by mzimmers
Thanks, Sprite.