Skip to main content
Visitor II
August 26, 2025
Solved

SPI Communication Issue with STM32G431K8T6

  • August 26, 2025
  • 1 reply
  • 302 views

Hello,

I am working with an STM32G431K8T6and using the LL library to configure SPI in master mode.
The issue is with the MISO pin (PB4).

  • The pin is configured as SPI input, with no pull-up or pull-down.

  • When PB4 is left unconnected, the voltage is measured at 3.3v.

  • If I short PB4 directly to GND, the current goes up to about 65mA, which looks like the pin is driving strongly,similar to push-pull output.

  • Because of this, the SPI slave cannot pull the line low enough, and communication fails.

Configuration Details:

void MX_SPI1_Init(void)
{

 /* USER CODE BEGIN SPI1_Init 0 */

 /* USER CODE END SPI1_Init 0 */

 LL_SPI_InitTypeDef SPI_InitStruct = {0};

 LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

 /* Peripheral clock enable */
 LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);

 LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
 LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOB);
 /**SPI1 GPIO Configuration
 PA7 ------> SPI1_MOSI
 PB3 ------> SPI1_SCK
 PB4 ------> SPI1_MISO
 */
 GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
 GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
 GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
 GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
 LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
 GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
 GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
 GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
 LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 GPIO_InitStruct.Pin = LL_GPIO_PIN_4;
 GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
 GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
 GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
 GPIO_InitStruct.Alternate = LL_GPIO_AF_5;
 LL_GPIO_Init(GPIOB, &GPIO_InitStruct);

 /* USER CODE BEGIN SPI1_Init 1 */

 /* USER CODE END SPI1_Init 1 */
 SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
 SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
 SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
 SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH;
 SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
 SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
 SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8;
 SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
 SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
 SPI_InitStruct.CRCPoly = 7;
 LL_SPI_Init(SPI1, &SPI_InitStruct);
 LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
 LL_SPI_DisableNSSPulseMgt(SPI1);
 /* USER CODE BEGIN SPI1_Init 2 */

 /* USER CODE END SPI1_Init 2 */

}

 Any help would be appreciated.

    This topic has been closed for replies.
    Best answer by TDK

    This is hardware issue, not a software one. No software configuration can cause PB4 to pull 65 mA.

    Figure out what PB4 is connected to on your board. Probably shorted to VDD somewhere.

    1 reply

    TDKAnswer
    Super User
    August 26, 2025

    This is hardware issue, not a software one. No software configuration can cause PB4 to pull 65 mA.

    Figure out what PB4 is connected to on your board. Probably shorted to VDD somewhere.