I try to send data from master to slave using SPI,
I'm really new to this and I dont know what im doing wrong
I dont know if its something with my init configuration or my understanding from spi proccess. if someone know or can guide me over cause Im out of clue what went wrong.
void SPI_init_master(void){
RCC->AHBENR |= RCC_AHBENR_GPIOBEN; // enable port b clock
RCC->APB2ENR |= RCC_APB2ENR_SPI1EN; // enable spi clock
GPIOB->MODER |= 0x00000A80; // Configure GPIOB pins 3 and 4 and 5 as alternate function 5
// AFR[0] is the same as AFRL in the reference manual (p. 241)
GPIOB->AFR[0] |= 0x00555000; // configure PB3-PB5
// SPI1->CR1 |= 0x0044; // enable SPI and Master configuration
SPI1->CR1 |= (SPI_CR1_SPE | SPI_CR1_MSTR);
}
void SPI_write(uint8_t ch){
*(__IO uint8_t *)&SPI1->DR = ch;
while(!(SPI1->SR & SPI_SR_TXE)); // wait until Transmit buffer empty will be 1 - finish to transmit data and the transmit buffer empty
print("spi_write - data in DR is: ");
USART2_printCharacter(ch);
print("\n");
}
char SPI_read(void)
{
char ch;
while(!(SPI1->SR & SPI_SR_RXNE));// wait until Receive buffer not empty will be 1 - finish to transmit data and the transmit buffer not empty
ch = SPI1->DR;
print("spi_read - data in DR is: ");
USART2_printCharacter(ch);
print("\n");
return ch;
}