Fix I2C signalStop in readLastByte for Microbit (#344)
* Fix I2C signalStop in readLastByte for Microbit
Этот коммит содержится в:
родитель
d90f1947d9
коммит
8d3f19bc84
1 изменённых файлов: 8 добавлений и 19 удалений
|
@ -185,21 +185,20 @@ func (i2c I2C) Tx(addr uint16, w, r []byte) error {
|
|||
}
|
||||
}
|
||||
if len(r) != 0 {
|
||||
// To trigger suspend task when a byte is received
|
||||
i2c.Bus.SHORTS = nrf.TWI_SHORTS_BB_SUSPEND
|
||||
i2c.Bus.TASKS_STARTRX = 1 // re-start transmission for reading
|
||||
for i := range r { // read each char
|
||||
if i+1 == len(r) {
|
||||
// The 'stop' signal must be sent before reading back the last
|
||||
// byte, so that it will be sent by the I2C peripheral right
|
||||
// after the last byte has been read.
|
||||
r[i] = i2c.readLastByte()
|
||||
} else {
|
||||
// To trigger stop task when last byte is received, set before resume task.
|
||||
i2c.Bus.SHORTS = nrf.TWI_SHORTS_BB_STOP
|
||||
}
|
||||
i2c.Bus.TASKS_RESUME = 1 // re-start transmission for reading
|
||||
r[i] = i2c.readByte()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Nothing to read back. Stop the transmission.
|
||||
i2c.signalStop()
|
||||
}
|
||||
i2c.Bus.SHORTS = nrf.TWI_SHORTS_BB_SUSPEND_Disabled
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -229,16 +228,6 @@ func (i2c I2C) readByte() byte {
|
|||
return byte(i2c.Bus.RXD)
|
||||
}
|
||||
|
||||
// readLastByte reads a single byte from the I2C bus, sending a stop signal
|
||||
// after it has been read.
|
||||
func (i2c I2C) readLastByte() byte {
|
||||
for i2c.Bus.EVENTS_RXDREADY == 0 {
|
||||
}
|
||||
i2c.Bus.EVENTS_RXDREADY = 0
|
||||
i2c.signalStop() // signal 'stop' now, so it is sent when reading RXD
|
||||
return byte(i2c.Bus.RXD)
|
||||
}
|
||||
|
||||
// SPI on the NRF.
|
||||
type SPI struct {
|
||||
Bus *nrf.SPI_Type
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче