mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
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:
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user