Skip to main content
Graduate
March 30, 2024
Solved

G431 SPI - bits are not set.

  • March 30, 2024
  • 1 reply
  • 1389 views

First time i set up SPI, not using HAL.

In the debug, i see that not a single bit is set.

What am i doing wrong?

 

 SPI_HandleTypeDef spiHandle;

 spiHandle.Instance = SPI2;

 // SPI_CR1_CPOL
 SET_BIT(spiHandle.Instance->CR1, SPI_BAUDRATEPRESCALER_256);

 // CPOL = 0
 SET_BIT(spiHandle.Instance->CR1, SPI_POLARITY_LOW);

 // CPHA = 1
 SET_BIT(spiHandle.Instance->CR1, SPI_PHASE_2EDGE);

 // MSB is default

 // We are Master
 SET_BIT(spiHandle.Instance->CR1, SPI_MODE_MASTER);

 // Active SPI
 SET_BIT(spiHandle.Instance->CR1, SPI_CR1_SPE);

 // Frame length
 SET_BIT(spiHandle.Instance->CR2, SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0);


 // SS output
 SET_BIT(spiHandle.Instance->CR2, SPI_CR2_SSOE );

 

    This topic has been closed for replies.
    Best answer by Tobe

    This is the solution:

    SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_SPI2EN);

    It was not mentioned in the SPI instructions...

    1 reply

    Super User
    March 30, 2024

    >What am i doing wrong?

    Not using HAL ? Why ?

    Just for fun ?

    Look in HAL lib, how its doing this, then you know.

     

    TobeAuthor
    Graduate
    March 30, 2024

    I rather like to read it in the manual, but i must have missed it? I followed the procedure in it.

    Also there a so many places where it the solution would be.

    I could set up the uart easily.

    Super User
    March 30, 2024

    G4xx SPI is not so complex :

    AScha3_0-1711834718359.png

    Maybe easy way: setup with Cube, then just write to DR ( SPI2->DR ) , as i do, to send.  :)

    (But i have no G4xx , just F303, etc. SPI seem same. On H7 or H5 its another game ! )