AnsweredAssumed Answered

SPI on STM32F207 IG

Question asked by kulshreshtha.samarth on Mar 1, 2014
Latest reply on Mar 2, 2014 by kulshreshtha.samarth
The registers aren't getting affected when I run the following code on the board. The clock is getting set however the SPI->CR1 register is not getting affected at all, upon debugging the code it shows only 0's.

#include <stm32f2xx.h>
#include <GPIO_STM32F2xx.h>
//#include "SPI_STM32F2xx.c"

void init123()
     RCC->AHB1ENR |= (0x01);   //IO port A clock enable for GPIO Pins for MOSI,MISO and SCK     
     //For configuring the above pins in SPI
     RCC->AHB1ENR |= (0x01<<3);  //IO port E clock enable fr GPIO Pins for Chip Select
     GPIOE->BSRRL |= (0x01<<6);  //For setting PE7 High
     SPI1->CR1 &= ~(0x01<<6);   //SPI Enable
     RCC->APB2ENR |= (0x01<<11);  //SPI clock enable     
     SPI1->CR1 &= ~(0x01<<15);   //Full Duplex mode     
     SPI1->CR1 |= (0x01<<2);   //SPI in Master Mode     
     SPI1->CR1 &= ~(0x01<<11);  //8 bit data format     
     SPI1->CR1 &= ~ (0x01<<1);   // CPOL - 0     
     SPI1->CR1 |= 0x01;    // CPHA - 1
     SPI1->CR1 &= ~(0x111<<3);  //Baud Rate 000 config     
     SPI1->CR1 &= ~ (0x01<<6);  // MSB First     
     SPI1->CR1 |= (0x01<<6);   //SPI Enable

uint8_t send123(uint8_t data)
     while (!(SPI1->SR & 0x10));  // wait until transmit complete
     while (!(SPI1->SR & 0x01));  // wait until receive complete
     while (!(SPI1->SR & 0x01<<6));  // wait until SPI is not busy anymore
     return SPI1->DR;

int main(void)
     uint8_t received_val = 0;     
               GPIOE->BSRRL |= (0x01<<6);  //For setting PE7 Low
               send123(0xAA);  // transmit data
               received_val = send123(0x00); // transmit dummy byte and receive data
               GPIOE->BSRRL |= (0x01<<6);  //For setting PE7 High