mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 20:43:40 +00:00
nrf: wait for stop condition after reading from the I2C bus
Found while working on the PineTime. For some reason it still kind of works in most cases, but I was hitting this issue when interacting with two different I2C devices (the touch sensor and the BMA421).
This commit is contained in:
committed by
Ron Evans
parent
cec237917f
commit
4619896c19
@@ -70,11 +70,16 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error) {
|
||||
i2c.Bus.SHORTS.Set(nrf.TWI_SHORTS_BB_SUSPEND_Disabled)
|
||||
}
|
||||
|
||||
// Stop explicitly when no reads were executed, stoping unconditionally would be a mistake.
|
||||
// It may execute after I2C peripheral has already been stopped by the shortcut in the read block,
|
||||
// so stop task will trigger first thing in a subsequent transaction, hanging it.
|
||||
if len(r) == 0 {
|
||||
// Stop the I2C transaction after the write.
|
||||
i2c.signalStop()
|
||||
} else {
|
||||
// The last byte read has already stopped the transaction, via
|
||||
// TWI_SHORTS_BB_STOP. But we still need to wait until we receive the
|
||||
// STOPPED event.
|
||||
for i2c.Bus.EVENTS_STOPPED.Get() == 0 {
|
||||
}
|
||||
i2c.Bus.EVENTS_STOPPED.Set(0)
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user