diff --git a/ports/stm32/pyb_i2c.c b/ports/stm32/pyb_i2c.c index 0cbb640473..9aac9274e0 100644 --- a/ports/stm32/pyb_i2c.c +++ b/ports/stm32/pyb_i2c.c @@ -478,8 +478,20 @@ void i2c_ev_irq_handler(mp_uint_t i2c_id) { } else { hi2c->Instance->DR = I2C_7BIT_ADD_READ(hi2c->Devaddress); } + hi2c->Instance->CR2 |= I2C_CR2_DMAEN; } else if (hi2c->Instance->SR1 & I2C_FLAG_ADDR) { __IO uint32_t tmp_sr2; + if (hi2c->State == HAL_I2C_STATE_BUSY_RX) { + if (hi2c->XferCount == 1U) { + hi2c->Instance->CR1 &= ~I2C_CR1_ACK; + } else { + if (hi2c->XferCount == 2U) { + hi2c->Instance->CR1 &= ~I2C_CR1_ACK; + hi2c->Instance->CR1 |= I2C_CR1_POS; + } + hi2c->Instance->CR2 |= I2C_CR2_LAST; + } + } tmp_sr2 = hi2c->Instance->SR2; UNUSED(tmp_sr2); } else if (hi2c->Instance->SR1 & I2C_FLAG_BTF && hi2c->State == HAL_I2C_STATE_BUSY_TX) {