This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI on STM32F407 Discovery not working

I am trying to program an F407VG manually without using CubeMX and using registers. Could someone please help me get the SPI running? When I look on an oscilloscope, the Slave/Chip select goes low and high correctly but I am writing data to SPI1 DR and I don't see anything on MOSI or SCLK. What have I done wrong? C code below:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* ENABLING AND CONFIGURING CLOCKS */
RCC->AHB1ENR |= (1<<0); //GPIO config
RCC->AHB1ENR |= (1<<4);
RCC->APB2ENR |= (1<<12); // SPI_1 Enabled
RCC->CR |= (1<<0); // Enable the 16 MHz HSI clock
RCC->PLLCFGR |= (0<<22); // Set HSI as source
RCC->PLLCFGR |= (1<<1) | (0<<0); // Adjust to use PLL
// Set the divider PLL_M to 16 to get 1 MHz since HSI is 16 MHz
RCC->PLLCFGR |= (0<<0) | (0<<1) | (0<<2) | (0<<3) | (1<<4) | (0<<5);
// SET PLL_N as 288
RCC->PLLCFGR |= (0<<6) | (0<<7) | (0<<8) | (0<<9) | (0<<10) | (1<<11) | (0<<12) | (0<<13) | (1<<14);
// Set PLL_P as 4 to get 72 MHz
RCC->PLLCFGR |= (1<<16) | (0<<17);
// Set APB2 divider to 2 to get 36 MHz
RCC->PLLCFGR |= (1<<15) | (0<<14) | (0<<13);
/*GPIO PINS*/
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

When running the code I set the CS pin to low and then write random data to the SPI1 DR like this:

GPIOE->BSRR |= (0<<5);
Delay by 10000
SPI1->DR |= (1<<7) | (1<<2);

Delay by 50
SPI1->DR |= (0<<7) | (0<<2);
Delay by 10000
GPIOE->BSRR |= (1<<5);


The delay is just a simple counter function. So in summary, I am configuring the HSI to be a source for PLL and then setting the division and multiplication factors such that the output frequency to APB/AHB is 72MHz. SPI1 is on APB2 so after dividing 72MHz by a prescaler of 2, I get 36 MHz as the clock frequency for SPI1 since I have read that SPI1 should be around 36 MHz. I have been through the code and registers again but I cannot find my error. Thank you for your help.

0