Skip to main content
MSipo
Senior II
September 8, 2023
Solved

STM32L4R9AII6 generates 16 SPI clock pulses when I have selected data size 8 in STM32CubeMX.

STM32L4R9AII6 generates 16 SPI clock pulses when I have selected data size 8 in STM32CubeMX.

When I measure the SPI clock when I write a single byte to the SPI1 DR register it outputs 16 clocks.

When I debug I can look at the SPI1 registers. The CR2 DS bits = 7. According to the datasheet this is 8 bits. But when I measure there is 16 clocks when I write a single byte to the DR register.

If I change the DS bit to 3 it will output 8 bits.

What is going on?

This topic has been closed for replies.
MSipo
MSipoBest answer
Senior II
September 8, 2023

I solved it. This ST32 has a packed mode in the DR register. So one must be careful to write to it as an uint8_t pointer to send 8 bits.

Like this:

*((__IO uint8_t *)&hspi1.Instance->DR) = data[i];

 

1 reply

MSipo
MSipoAuthorBest answer
Senior II
September 8, 2023

I solved it. This ST32 has a packed mode in the DR register. So one must be careful to write to it as an uint8_t pointer to send 8 bits.

Like this:

*((__IO uint8_t *)&hspi1.Instance->DR) = data[i];