Skip to main content
Rikerq
Associate II
June 23, 2020
Solved

STM32L552 - trying to set 3 GPIO Pins as inputs(w/ wo pull-downs) to be read before most initialization, but some pins on the board are always HIGH?

  • June 23, 2020
  • 1 reply
  • 895 views

I'm trying to use 3 GPIO Pins as a 3-bit ID essentially. Depending on the values read, the uC will configure itself in an appropriate way (1 bin fits all tools essentially). The problem I'm having is that with the eval board the pins are pretty close together, so I can only fit my jumper wires on the top corner pins of each section, vastly limiting the number i can test with.

I can get 2 pins that consistently behave correctly when I have the inputs driven/not driven, but the 3rd is always on a pin that constantly be in a HIGH state even at initialization. How do I fix this?

int main(void)
{
 /* USER CODE BEGIN 1 */
 
 /* USER CODE END 1 */
 
 /* MCU Configuration--------------------------------------------------------*/
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 HAL_Init();
 
 /* USER CODE BEGIN Init */
 Configure_Card_GPIO_Init();
 Configure_Card_Type(gpioSelection);
....
 
}
static void Configure_Card_Type(int gpio_lines)
{
	uint8_t cal_value = 0;
	cal_value += HAL_GPIO_ReadPin(GPIO_CAL_E13_GPIO_Port, GPIO_CAL_E13_Pin);
	cal_value = cal_value << 1;
	cal_value += HAL_GPIO_ReadPin(GPIO_CAL_F11_GPIO_Port, GPIO_CAL_F11_Pin);
	cal_value = cal_value << 1;
	cal_value += HAL_GPIO_ReadPin(GPIO_CAL_E0_GPIO_Port, GPIO_CAL_E0_Pin);
 
.... do things
}
 
static void Configure_Card_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 
 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOE_CLK_ENABLE();
 __HAL_RCC_GPIOF_CLK_ENABLE();
 
 
 /*Configure GPIO pins : GPIO_CAL_E1_Pin GPIO_CAL_E2_Pin GPIO_CAL_E0_Pin */
 GPIO_InitStruct.Pin = GPIO_CAL_E13_Pin|GPIO_CAL_E14_Pin|GPIO_CAL_E0_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
 HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
 
 /*Configure GPIO pin : GPIO_CAL_F11_Pin */
 GPIO_InitStruct.Pin = GPIO_CAL_F11_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
 HAL_GPIO_Init(GPIO_CAL_F11_GPIO_Port, &GPIO_InitStruct);
 
}

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

Double check that the pin is not connected to anything else. There is no reason it shouldn't behave the same as the other pins. There has to be a reason either in the code, the board, or possibly due to damage. Nothing special about any of the pins you're trying that I can think of.

Set the pin as GPIO and see if you can toggle it high and low.

1 reply

TDK
TDKBest answer
June 24, 2020

Double check that the pin is not connected to anything else. There is no reason it shouldn't behave the same as the other pins. There has to be a reason either in the code, the board, or possibly due to damage. Nothing special about any of the pins you're trying that I can think of.

Set the pin as GPIO and see if you can toggle it high and low.

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