Skip to main content
Associate II
March 31, 2025
Solved

STM32G070 wrong SPI SCK IDLE state after turn on

  • March 31, 2025
  • 1 reply
  • 602 views

Hi folks

I have a problem that seems to common in the SPI field, specifically the idle state of the SCK pin. My application needs a clock low idle state and after the turn on, it goes to high, corrupting the communication with an external SPI flash memory. I'm using STM32 CubeIDE 1.18.0

I read here in the forum and internet two workarounds:

1.- Turn on the pull-down resistor on the SCK pin.

2.- Send a dummy byte without changing the CS state.

But those are good methods? What is the advice in this case?

Here is the SPI init code:

static void MX_SPI1_Init(void)
{

 /* USER CODE BEGIN SPI1_Init 0 */

 /* USER CODE END SPI1_Init 0 */

 /* USER CODE BEGIN SPI1_Init 1 */

 /* USER CODE END SPI1_Init 1 */
 /* SPI1 parameter configuration*/
 hspi1.Instance = SPI1;
 hspi1.Init.Mode = SPI_MODE_MASTER;
 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
 hspi1.Init.NSS = SPI_NSS_SOFT;
 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
 hspi1.Init.CRCPolynomial = 7;
 hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
 hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
 if (HAL_SPI_Init(&hspi1) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN SPI1_Init 2 */

 /* USER CODE END SPI1_Init 2 */

}


And screenshoot of the logic analizer in the first byte sended.
spi_sck_state.png

Best regards 

Best answer by Uwe Bonnes

To keep SCLK low during bootup, use a pull down. The pull down only gets into effect when the uC has booted, but it should be activated anyways.

1 reply

Uwe Bonnes
Uwe BonnesBest answer
Chief
April 1, 2025

To keep SCLK low during bootup, use a pull down. The pull down only gets into effect when the uC has booted, but it should be activated anyways.

Associate II
April 2, 2025

For deadline propuses, I just activated the pulldown resistor and it works! But that is the best way to accomplish it?

Best regards and thanks