2024-03-30 02:11 PM
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 );
Solved! Go to Solution.
2024-03-30 03:31 PM
This is the solution:
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_SPI2EN);
It was not mentioned in the SPI instructions...
2024-03-30 02:28 PM
>What am i doing wrong?
Not using HAL ? Why ?
Just for fun ?
Look in HAL lib, how its doing this, then you know.
2024-03-30 02:31 PM - edited 2024-03-30 02:33 PM
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.
2024-03-30 02:41 PM - edited 2024-03-30 02:43 PM
G4xx SPI is not so complex :
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 ! )
2024-03-30 03:31 PM
This is the solution:
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_SPI2EN);
It was not mentioned in the SPI instructions...