work on spi implementation

interrupts
polymurph 3 years ago
parent 13a14dcb11
commit 4f84e43b91

@ -25,13 +25,13 @@ extern "C" {
/** This is the spi hardware channel class*/
void spi_initMaster(spiCH_t spic_hw_ch);
void spi_initMaster(spiCH_t spi_hw_ch);
/*!
* @brief Transmits and receives on byte of data
* @param spi_hw_ch SPI hardware channel
* @param tx_data 'tx_data' The pyte to be transmitted"
* @param tx_data 'tx_data' The byte to be transmitted"
* @return The received data
*/
uint8_t spi_trx(spiCH_t spi_hw_ch, uint8_t tx_data);

@ -29,3 +29,9 @@ target_compile_definitions(stmTimer PRIVATE ${C_DEFS})
target_include_directories(stmTimer PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES})
add_library(sub::timer ALIAS stmTimer)
add_library(stmSPI spi.c)
target_compile_options(stmSPI PRIVATE ${C_FLAGS})
target_compile_definitions(stmSPI PRIVATE ${C_DEFS})
target_include_directories(stmSPI PUBLIC ${INTERFACES_DIR} ${CSL_INCLUDES})
add_library(sub::spi ALIAS stmSPI)

@ -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
}

@ -77,3 +77,4 @@ list(APPEND EXTRA_LIBS sub::pin)
list(APPEND EXTRA_LIBS sub::usart)
list(APPEND EXTRA_LIBS sub::timer)
list(APPEND EXTRA_LIBS sub::init)
list(APPEND EXTRA_LIBS sub::spi)

@ -77,10 +77,11 @@ int main(int argc, char *argv[])
pinWrite(pinB3,0);
spi_initMaster(SPI_CH_1);
while(1) {
for(i = 10; i > 0; i--) {
spi_trx(SPI_CH_1, 0xAE);
}
pinWrite(pinB3,1);
//timer_capture_compare_test(timer_2);
//print_Usart(usart2, "All is working fine \r\n");

@ -6,7 +6,7 @@ echo $dir
tmux new -s 'git' -d 'fish'
tmux new -s 'compile' -d 'fish'
tmux new -s 'main' -d 'vim main.cpp'
tmux new -s 'main' -d 'fish'
cd $dir/ked/csl/stm32f042/Src/
tmux new -s 'src' -d 'fish'
@ -17,4 +17,7 @@ tmux new -s 'device' -d 'fish'
cd $dir/ked/csl/interfaces/
tmux new -s 'interface' -d 'fish'
cd $dir/ked/
tmux new -s 'KED submodule' -d 'fish'
tmux a

Loading…
Cancel
Save