cancel
Showing results for 
Search instead for 
Did you mean: 

stm32cubeMx generate LL init function void MX_SPI2_Init(void) but th e function is not correct in slave mode.

Jos Poelmans
Associate II

first line in function MX_SPI2_Init()

 LL_SPI_InitTypeDef SPI_InitStruct; is not filled with zero's

and baudrate is not set for slave mode.

But in in funtion LL_SPI_Init baurate is filled in an the destruct SPI CR1 register.

I have there fore init the struct to zero and then there is no moer problem

 LL_SPI_InitTypeDef SPI_InitStruct = {0};

2 REPLIES 2
Jos Poelmans
Associate II

See in question ther is an answer for the problem.

I hope the Stm32cubeMx will look to the problem en generate in a new version

a better code.

Amel NASRI
ST Employee

Hi @Jos Poelmans​ ,

I am using STM32CubeMX 4.26.1 with STM32L052R6Hx, and I see baudrate field initiated as following in MX_SPI2_Init:

SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;

This is the default configuration when enabling SPI2.

Are we using different CubeMX versions? Which device did you selected? May be if you can share a .ioc file.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.