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
This commit is contained in:
Thomas Kohler
2025-08-21 18:05:21 +02:00
committed by Ron Evans
parent 13bb59c334
commit 381644a0c0
+3 -3
View File
@@ -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())
}
}