From 381644a0c05ef724e00a03ef9b38da88134fe4a7 Mon Sep 17 00:00:00 2001 From: Thomas Kohler Date: Thu, 21 Aug 2025 18:05:21 +0200 Subject: [PATCH] machine,nrf528: stop the bus only once on I2C bus error and ensures the first error is returned In some cases, e.g nothing connected on the bus, repeated resume-stop sequences can lead to the bus never reaching the stop state, hanging Tx. This change ensures the resume-stop sequence is submitted once on error. It also moves the error code read to before the sequence to ensure it's valid. Fixes: #4998 --- src/machine/machine_nrf528xx.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/machine/machine_nrf528xx.go b/src/machine/machine_nrf528xx.go index f8937aec0..bbcc8fb03 100644 --- a/src/machine/machine_nrf528xx.go +++ b/src/machine/machine_nrf528xx.go @@ -78,14 +78,14 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error) { // Allow scheduler to run gosched() - // Handle errors by ensuring STOP sent on bus - if i2c.Bus.EVENTS_ERROR.Get() != 0 { + // Handle first occurrence of error by ensuring STOP sent on bus + if err == nil && i2c.Bus.EVENTS_ERROR.Get() != 0 { + err = twiCError(i2c.Bus.ERRORSRC.Get()) if i2c.Bus.EVENTS_STOPPED.Get() == 0 { // STOP cannot be sent during SUSPEND i2c.Bus.TASKS_RESUME.Set(1) i2c.Bus.TASKS_STOP.Set(1) } - err = twiCError(i2c.Bus.ERRORSRC.Get()) } }