|
|
|
@ -4,7 +4,7 @@
|
|
|
|
|
|
|
|
|
|
// https://controllerstech.com/spi-using-registers-in-stm32/
|
|
|
|
|
|
|
|
|
|
void spi_initMater(spiCH_t_spi_hw_ch)
|
|
|
|
|
void spi_initMater(spiCH_t spi_hw_ch)
|
|
|
|
|
{
|
|
|
|
|
RCC->APB2ENR |= (1<<12); // Enable SPI1 CLock
|
|
|
|
|
|
|
|
|
@ -25,8 +25,23 @@ void spi_initMater(spiCH_t_spi_hw_ch)
|
|
|
|
|
SPI1->CR2 = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t spi_trx(spiCH_t_spi_hw_ch, uint8_t tx_data)
|
|
|
|
|
uint8_t spi_trx(spiCH_t spi_hw_ch, uint8_t tx_data)
|
|
|
|
|
{
|
|
|
|
|
uint8_t data;
|
|
|
|
|
// example
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (((SPI1->SR)&(1<<7))); // wait for BSY bit to Reset -> This will indicate that SPI is not busy in communication
|
|
|
|
|
|
|
|
|
|
SPI1->DR = tx_data; // send data
|
|
|
|
|
|
|
|
|
|
while (!((SPI1->SR) &(1<<0))); // Wait for RXNE to set -> This will indicate that the Rx buffer is not empty
|
|
|
|
|
data = SPI1->DR;
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
|
|
// implementation 2. step
|
|
|
|
|
#if 0
|
|
|
|
|
// wait for SPY ready
|
|
|
|
|
while((SPI_BASE->SR) & (1 << 7));
|
|
|
|
|
|
|
|
|
@ -37,4 +52,5 @@ uint8_t spi_trx(spiCH_t_spi_hw_ch, uint8_t tx_data)
|
|
|
|
|
while(!((SPI_BASE->SR) & (1<<0));
|
|
|
|
|
|
|
|
|
|
return SPI_BASE->DR;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|