I am trying to setup the SPI. I followed the logic from other tutorials but with no success. Can someone point me in the right direction?
void spi_setup(void) {
RCC_AHBENR |= _BV(17); //IOPAEN
RCC_APB2ENR |= _BV(12); //SPI1EN
GPIOA_OSPEED |= 0x11<<7 | 0x11<<6 | 0x11<<5; //GPIO CLOCK SPEED
GPIOA_MODER |= _BV(5*2+1)/*AFM*/ | _BV(6*2+1)/*AFM*/ | _BV(7*2+1)/*AFM*/;
GPIOA_AFRL |= 0;
//GPIOA_OTYPER = _BV(7) | _BV(6) | _BV(5); //output OPEN-DRAIN
//GPIOA_PUPDR |= _BV(7*2+1)/*pull DOWN*/ | _BV(6*2+1)/*pull DOWN*/ | _BV(5*2+1)/*pull DOWN*/;
SPI1_CR2 |= 0x111<<8/*8B data size*/;
SPI1_CR1 = _BV(9)/*Soft slave man*/ | _BV(6)/*SPI Enable*/| (0x0<<3)/*BaudRate*/ | _BV(2)/*Master*/ | _BV(0)/*Clock Polarity*/;
}
void spi_tx (uint8_t send) {
while ( SPI1_SR & _BV(7) ) {} /*while BUSY WAIT */
SPI1_DR = send;
}