Skip to content

i2c_write_timeout_per_char_us will never Time out #844

@slaycrit

Description

@slaycrit

I had a problem where unresponsive Devices on the I2C would get the entire Pico stuck.
Drilling into a few functions i found the Timeout Check called in i2c_write_blocking_internal:

        do {
            if (timeout_check) {
                timeout = timeout_check(ts); // <-- This guy right here
                abort |= timeout;
            }
            tight_loop_contents();
        } while (!timeout && !(i2c->hw->raw_intr_stat & I2C_IC_RAW_INTR_STAT_TX_EMPTY_BITS));

... which is called in a loop and also sets a new timeout point Here in the timeout_check function (points to check_per_iteration_timeout_us in timeout_helper.c):

static bool check_per_iteration_timeout_us(timeout_state_t *ts) {
    if (time_reached(ts->next_timeout)) {
        return true;
    }
    ts->next_timeout = make_timeout_time_us(ts->param); // <-- New Timeout here
    return false;
}

Tldr: Timeout Check resets the Timeout

As far as i can see the i2c_write_timeout_us should not have this issue and can be used instead as a quick fix.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions