2022-11-08 08:02 AM
Hello
I am using nucleo G031K8 with STM32 cube ide and I am trying to initialize the SPI1 peripheral with registers.
Here is my init code and the corresponding wrong registers. The RCC and GPIO registers are fine. Only SPI1 registers are wrong
How can I solve this?
Thanks
Solved! Go to Solution.
2022-11-08 08:49 AM
2022-11-08 08:49 AM
2022-11-08 10:20 AM
Another one with the magic numbers instead of normal CMSIS defined bit-field names. They all use peripheral handles and structures, but don't use bit-field defines. And of course, none of them knows that a simple integer number by default is of a signed type and will fail with right-shifting under some scenarios, especially related to the highest bit.
From where does this trend come? Educational institutions/courses/material?
2022-11-09 02:55 AM
Hi @Community member and @Piranha
Thanks a lot for the useful replies.
Having the SSOE bit enabled made SPI working as I expected. I also managed to use the CMSIS defined bit-field names ( the issue was not related to this but I do agree that they must be used)
SPI1-> CR1 |= SPI_CR1_BR_2|SPI_CR1_BR_1|SPI_CR1_BR_0|SPI_CR1_MSTR;
SPI1->CR2|= SPI_CR2_SSOE|SPI_CR2_DS_3;
SPI1->CR2&= ~(SPI_CR2_DS_2|SPI_CR2_DS_1);
SPI1->CR1 |= SPI_CR1_SPE;
This is the SPI related part.
2022-11-09 03:45 AM
Where do you see a right shift? )) Left, left everywhere...
2022-11-10 01:22 PM
It will happen when they will copy paste that code in some other code. Or when they finally decide to define some macro... :)