Skip to main content
Associate III
March 19, 2025
Solved

Why can't I get the SPI clock to idle low

  • March 19, 2025
  • 2 replies
  • 860 views

I'm working on a STM32H755ZIQ.  I am setting up a SPI master, with CPol= 0, CPha = 1, accordingly I need the clock to be low when inactive.  Additionally I want the clock to be low when idling, even when the SPI is not active. To achieve this, I have modified the GPIO settings to use a pulldown resistor on the clock pin.

I set this up using the CubeMX utility, but I don't necessarily trust it, so I have checked the generated code, and I find, in main.c, within the function MX_SPI1_Init(void), the polarity is set low:

TomC1_0-1742391694539.png

and also, in stm32h7xx_hal_msp.c, within the function HAL_SPI_MspInit(SPI_HandleTypeDef* hspi), the GPIO is set to use the pulldown resistor:

TomC1_1-1742391813142.png

And yet, the clock is idling high. You can see in the logic trace below, that the clock is NOT normally pulled down, but only goes low when the SPI is activated.  

TomC1_2-1742391925483.png

I assert the CS pin before carrying out an SPI write operation. The clock is still high when the slave detects the CS change, and the slave fails to correctly read the data.

 

Can anyone tell me what more I need to do to ensure that the clock like is idling low?

Thanks

 

Best answer by TDK

When the peripheral is disabled, the pin will float unless you set it to keep the IO state here:

TDK_0-1742393214253.png

 

2 replies

Uwe Bonnes
Chief
March 19, 2025

Did you try to set the pull functionality of the GPIO pin  to the right direction and pull active?

TDK
TDKBest answer
Super User
March 19, 2025

When the peripheral is disabled, the pin will float unless you set it to keep the IO state here:

TDK_0-1742393214253.png

 

"If you feel a post has answered your question, please click ""Accept as Solution""."