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     
     
     GPIO_PinConfigure(GPIOA,5,GPIO_MODE_AF,GPIO_OUTPUT_PUSH_PULL,GPIO_OUTPUT_SPEED_50MHz,GPIO_NO_PULL_UP_DOWN); //For PA5
     GPIO_PinConfigure(GPIOA,6,GPIO_MODE_AF,GPIO_OUTPUT_PUSH_PULL,GPIO_OUTPUT_SPEED_50MHz,GPIO_NO_PULL_UP_DOWN); //For PA6
     GPIO_PinConfigure(GPIOA,7,GPIO_MODE_AF,GPIO_OUTPUT_PUSH_PULL,GPIO_OUTPUT_SPEED_50MHz,GPIO_NO_PULL_UP_DOWN); //For PA7
     
     //For configuring the above pins in SPI
     GPIO_PinAF (GPIOA,5,GPIO_AF_SPI1);
     GPIO_PinAF (GPIOA,6,GPIO_AF_SPI1);
     GPIO_PinAF (GPIOA,7,GPIO_AF_SPI1);
     
     RCC->AHB1ENR |= (0x01<<3);  //IO port E clock enable fr GPIO Pins for Chip Select
     
     GPIO_PinConfigure(GPIOE,7,GPIO_MODE_OUTPUT,GPIO_OUTPUT_PUSH_PULL,GPIO_OUTPUT_SPEED_50MHz,GPIO_PULL_UP); //For Chip Select - PE7
     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)
{
     SPI1->DR=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;     
     init123();
     while(1)
          {
               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
          }


}

Outcomes