cancel
Showing results for 
Search instead for 
Did you mean: 

G431 SPI - bits are not set.

Tobe
Senior III

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 );

 

1 ACCEPTED SOLUTION

Accepted Solutions

This is the solution:

SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_SPI2EN);

It was not mentioned in the SPI instructions...

View solution in original post

4 REPLIES 4
AScha.3
Chief II

>What am i doing wrong?

Not using HAL ? Why ?

Just for fun ?

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

 

If you feel a post has answered your question, please click "Accept as Solution".

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.

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 ! )

If you feel a post has answered your question, please click "Accept as Solution".

This is the solution:

SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_SPI2EN);

It was not mentioned in the SPI instructions...