Internal Pull up STM32G4 series
Hello,
I am using the internal pull up for the input pins, but when read the port status using the program, it always reads 0 instead of 1. I expected it to read 1 and if make that pin grounded it shall read 0.
Hello,
I am using the internal pull up for the input pins, but when read the port status using the program, it always reads 0 instead of 1. I expected it to read 1 and if make that pin grounded it shall read 0.
I couldn´t see anything wrong in your code. I tried to do some easy example and it works right and pin input value is also seen in debugger. Do you have connected anything externally to MCU pins?
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
while (1)
{
HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin,
HAL_GPIO_ReadPin(INPUT_PULL_UP_GPIO_Port, INPUT_PULL_UP_Pin));
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(USER_LED_GPIO_Port, USER_LED_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : INPUT_PULL_UP_Pin */
GPIO_InitStruct.Pin = INPUT_PULL_UP_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(INPUT_PULL_UP_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : USER_LED_Pin */
GPIO_InitStruct.Pin = USER_LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(USER_LED_GPIO_Port, &GPIO_InitStruct);
}
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.