diff --git a/ked/csl/stm32f042/Device/hardwareDescription.h b/ked/csl/stm32f042/Device/hardwareDescription.h index 70dafba..7018153 100644 --- a/ked/csl/stm32f042/Device/hardwareDescription.h +++ b/ked/csl/stm32f042/Device/hardwareDescription.h @@ -236,7 +236,10 @@ typedef enum{ SPI_CH_2 } spiCH_t; - +static const uint32_t spiBase_Addr_List[MAX_SPI_CHANNEL_COUNT] = { + SPI1_BASE, + SPI2_BASE +}; #ifdef __cplusplus diff --git a/ked/csl/stm32f042/Src/spi.c b/ked/csl/stm32f042/Src/spi.c index 7de72d1..f272ac1 100644 --- a/ked/csl/stm32f042/Src/spi.c +++ b/ked/csl/stm32f042/Src/spi.c @@ -1,5 +1,7 @@ #include "spi.h" +#define SPI_BASE ((SPI_TypeDef *)spiBase_Addr_List[spi_hw_ch]) + // https://controllerstech.com/spi-using-registers-in-stm32/ void spi_initMater(spiCH_t_spi_hw_ch) @@ -25,5 +27,14 @@ void spi_initMater(spiCH_t_spi_hw_ch) uint8_t spi_trx(spiCH_t_spi_hw_ch, uint8_t tx_data) { - return 0; + // wait for SPY ready + while((SPI_BASE->SR) & (1 << 7)); + + // load tx data + SPI_BASE->DR = tx_data; + + // Wait for RXNE flag to be set which indicates transmit complete + while(!((SPI_BASE->SR) & (1<<0)); + + return SPI_BASE->DR; }