kopia lustrzana https://github.com/micropython/micropython
stm32/i2c: Fix num_acks calculation in i2c_write for F0 and F7 MCU's.
Due to buffering of outgoing bytes on the I2C bus, detection of a NACK using the ISR_NACKF flag needs to account for the case where ISR_NACKF corresponds to the previous-to-previous byte.pull/3861/merge
rodzic
37a7257aff
commit
bc5e8a2cb6
|
@ -421,8 +421,13 @@ int i2c_write(i2c_t *i2c, const uint8_t *src, size_t len, size_t next_len) {
|
||||||
if ((ret = i2c_wait_isr_set(i2c, I2C_ISR_TCR | I2C_ISR_TC | I2C_ISR_STOPF))) {
|
if ((ret = i2c_wait_isr_set(i2c, I2C_ISR_TCR | I2C_ISR_TC | I2C_ISR_STOPF))) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (i2c->ISR & I2C_ISR_NACKF) {
|
uint32_t isr = i2c->ISR;
|
||||||
|
if (isr & I2C_ISR_NACKF) {
|
||||||
// Slave did not respond to byte so stop sending
|
// Slave did not respond to byte so stop sending
|
||||||
|
if (!(isr & I2C_ISR_TXE)) {
|
||||||
|
// The TXDR is still full so the byte previous to that wasn't actually ACK'd
|
||||||
|
--num_acks;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++num_acks;
|
++num_acks;
|
||||||
|
|
Ładowanie…
Reference in New Issue