diff --git a/ports/stm32/i2c.c b/ports/stm32/i2c.c index e0eea90ab7..109b9418f8 100644 --- a/ports/stm32/i2c.c +++ b/ports/stm32/i2c.c @@ -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))) { 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 + if (!(isr & I2C_ISR_TXE)) { + // The TXDR is still full so the byte previous to that wasn't actually ACK'd + --num_acks; + } break; } ++num_acks;