Skip to content

I2C master read/write error handling mechanism #557

@Pinkman624

Description

@Pinkman624

“If an error occurs during an I2C read/write operation (e.g., the slave device is powered off during the transfer), i2c_master_read_sync in i2c_master.c only waits on yield_for(&ready) without checking the returned status. Consequently, i2c_master_read_sync reports success even when the I2C transaction fails.”

int i2c_master_read_sync(uint16_t address, uint8_t* buffer, uint16_t len) {
bool ready = 0;
int rval = i2c_master_set_buffer(buffer, len);
if (rval < 0) return rval;

rval = i2c_master_set_callback(i2c_callback, &ready);
if (rval < 0) return rval;

rval = i2c_master_read(address, len);
if (rval < 0) return rval;

yield_for(&ready);
return RETURNCODE_SUCCESS;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions