From 32b980c052071b215481a29396b0f80575b58f2d Mon Sep 17 00:00:00 2001 From: DiSlord Date: Mon, 16 Sep 2024 23:06:39 +0300 Subject: [PATCH] Fix I2C read (more safe) --- NANOVNA_STM32_F072/i2c_v2.c | 1 + NANOVNA_STM32_F303/i2c_v2.c | 1 + 2 files changed, 2 insertions(+) diff --git a/NANOVNA_STM32_F072/i2c_v2.c b/NANOVNA_STM32_F072/i2c_v2.c index c7d99f6d..5707a084 100644 --- a/NANOVNA_STM32_F072/i2c_v2.c +++ b/NANOVNA_STM32_F072/i2c_v2.c @@ -51,6 +51,7 @@ bool i2c_transfer(uint8_t addr, const uint8_t *w, size_t wn) // I2C TX and RX variant bool i2c_receive(uint8_t addr, const uint8_t *w, size_t wn, uint8_t *r, size_t rn) { + while(VNA_I2C->ISR & I2C_ISR_BUSY); // wait last transaction VNA_I2C->CR1|= I2C_CR1_PE; if (wn) { VNA_I2C->CR2 = (addr << I2C_CR2_SADD_7BIT_SHIFT) | (wn << I2C_CR2_NBYTES_SHIFT); diff --git a/NANOVNA_STM32_F303/i2c_v2.c b/NANOVNA_STM32_F303/i2c_v2.c index fb7cde4d..7bed39dc 100644 --- a/NANOVNA_STM32_F303/i2c_v2.c +++ b/NANOVNA_STM32_F303/i2c_v2.c @@ -51,6 +51,7 @@ bool i2c_transfer(uint8_t addr, const uint8_t *w, size_t wn) // I2C TX and RX variant bool i2c_receive(uint8_t addr, const uint8_t *w, size_t wn, uint8_t *r, size_t rn) { + while(VNA_I2C->ISR & I2C_ISR_BUSY); // wait last transaction VNA_I2C->CR1|= I2C_CR1_PE; if (wn) { VNA_I2C->CR2 = (addr << I2C_CR2_SADD_7BIT_SHIFT) | (wn << I2C_CR2_NBYTES_SHIFT);