From 96cf6692217c0cd6b4518557407654f4802eada9 Mon Sep 17 00:00:00 2001 From: Navendu Pottekkat Date: Thu, 13 Aug 2026 14:41:53 +0530 Subject: [PATCH 1/3] fix: remove incorrect !readLast check Signed-off-by: Navendu Pottekkat --- src/machine/machine_esp32_i2c.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/machine/machine_esp32_i2c.go b/src/machine/machine_esp32_i2c.go index 746e722dc2..abcc2b4c94 100644 --- a/src/machine/machine_esp32_i2c.go +++ b/src/machine/machine_esp32_i2c.go @@ -242,7 +242,6 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { timeoutNS := int64(timeoutMS) * 1000000 needAddress := true needRestart := false - readLast := false var readTo []byte for cmdIdx, reg := 0, &i2c.Bus.COMD0; cmdIdx < len(cmd); { c := &cmd[cmdIdx] @@ -310,7 +309,6 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { } if split { - readLast = true reg.Set(i2cCMD_READLAST | 1) reg = nextAddress(reg) readTo = c.data[c.head : c.head+bytes+1] // read bytes + 1 last byte @@ -342,7 +340,7 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { } } switch { - case mask&esp.I2C_INT_STATUS_ACK_ERR_INT_ST_Msk != 0 && !readLast: + case mask&esp.I2C_INT_STATUS_ACK_ERR_INT_ST_Msk != 0: return errI2CAckExpected case mask&esp.I2C_INT_STATUS_TIME_OUT_INT_ST_Msk != 0: // timeout leaves the bus in an undefined state, reset From 66eb4dfe1c5f1d6c4afc007556db7f14965768ae Mon Sep 17 00:00:00 2001 From: Navendu Pottekkat Date: Sun, 16 Aug 2026 22:18:41 +0530 Subject: [PATCH 2/3] chore: copy fix to esp32xx Signed-off-by: Navendu Pottekkat --- src/machine/machine_esp32xx_i2c.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/machine/machine_esp32xx_i2c.go b/src/machine/machine_esp32xx_i2c.go index ed0e686d69..3bb1a4fb62 100644 --- a/src/machine/machine_esp32xx_i2c.go +++ b/src/machine/machine_esp32xx_i2c.go @@ -186,7 +186,6 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { timeoutNS := int64(timeoutMS) * 1000000 needAddress := true needRestart := false - readLast := false var readTo []byte for cmdIdx, reg := 0, &i2c.Bus.COMD0; cmdIdx < len(cmd); { c := &cmd[cmdIdx] @@ -254,7 +253,6 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { reg = nextAddress(reg) } if split { - readLast = true reg.Set(i2cCMD_READLAST | 1) reg = nextAddress(reg) readTo = c.data[c.head : c.head+bytes+1] // read bytes + 1 last byte @@ -285,7 +283,7 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { } } switch { - case mask&esp.I2C_INT_STATUS_NACK_INT_ST_Msk != 0 && !readLast: + case mask&esp.I2C_INT_STATUS_NACK_INT_ST_Msk != 0: return errI2CAckExpected case mask&esp.I2C_INT_STATUS_TIME_OUT_INT_ST_Msk != 0: if readTo != nil { From dc9e27de290096da99d3ea0ca459b72d7915b2c9 Mon Sep 17 00:00:00 2001 From: Navendu Pottekkat Date: Sun, 16 Aug 2026 22:28:08 +0530 Subject: [PATCH 3/3] fix: reset bus Signed-off-by: Navendu Pottekkat --- src/machine/machine_esp32_i2c.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/machine/machine_esp32_i2c.go b/src/machine/machine_esp32_i2c.go index abcc2b4c94..2f3a0d9753 100644 --- a/src/machine/machine_esp32_i2c.go +++ b/src/machine/machine_esp32_i2c.go @@ -341,6 +341,8 @@ func (i2c *I2C) transmit(addr uint16, cmd []i2cCommand, timeoutMS int) error { } switch { case mask&esp.I2C_INT_STATUS_ACK_ERR_INT_ST_Msk != 0: + // a NACK leaves the bus in an undefined state, reset + i2c.resetBus() return errI2CAckExpected case mask&esp.I2C_INT_STATUS_TIME_OUT_INT_ST_Msk != 0: // timeout leaves the bus in an undefined state, reset