From f100d75c19709e92fd07423217e76031acbad8a6 Mon Sep 17 00:00:00 2001 From: Yannic Schroeder Date: Wed, 12 Dec 2018 15:25:07 +0100 Subject: [PATCH] stm32f1: Always read SPI receive buffer Otherwise the first byte read via SPI may be the last byte of the previous transfer Signed-off-by: Yannic Schroeder --- src/stm32f1/spi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/stm32f1/spi.c b/src/stm32f1/spi.c index 7bea6cb5..a90a030a 100644 --- a/src/stm32f1/spi.c +++ b/src/stm32f1/spi.c @@ -97,9 +97,10 @@ spi_transfer(struct spi_config config, uint8_t receive_data, while (len--) { LL_SPI_TransmitData8(SPI2, *data); while (!LL_SPI_IsActiveFlag_TXE(SPI2)); + while (!LL_SPI_IsActiveFlag_RXNE(SPI2)); + uint8_t rdata = LL_SPI_ReceiveData8(SPI2); if (receive_data) { - while (!LL_SPI_IsActiveFlag_RXNE(SPI2)); - *data = LL_SPI_ReceiveData8(SPI2); + *data = rdata; } data++; }