Commit a707fe50 authored by Damien George's avatar Damien George

rp2/machine_i2c: Use soft I2C only for len=0, and increase timeout.

The RP2040 I2C hardware can do writes of length 1 and 2, just not of length
0.  So only use software I2C for writes of length 0, to improve
performance.

Also increase the software I2C timeout for zero-length writes to
accommodate the behaviour of a wider range of I2C devices.

Fixes issue #8167.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent bef26d4e
......@@ -127,12 +127,12 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
if (flags & MP_MACHINE_I2C_FLAG_READ) {
ret = i2c_read_blocking(self->i2c_inst, addr, buf, len, nostop);
} else {
if (len <= 2) {
// Workaround issue with hardware I2C not accepting short writes.
if (len == 0) {
// Workaround issue with hardware I2C not accepting zero-length writes.
mp_machine_soft_i2c_obj_t soft_i2c = {
.base = { &mp_machine_soft_i2c_type },
.us_delay = 500000 / self->freq + 1,
.us_timeout = 255,
.us_timeout = 50000,
.scl = self->scl,
.sda = self->sda,
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment