cancel
Showing results for 
Search instead for 
Did you mean: 

SPI1 initialization without HAL

Tommino
Senior

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

0693W00000WHm3KQAT.pngHow can I solve this?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
Piranha
Chief II

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?

Tommino
Senior

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.

Where do you see a right shift? )) Left, left everywhere...

It will happen when they will copy paste that code in some other code. Or when they finally decide to define some macro... 🙂