Skip to main content
Qsdxkh
Associate II
January 31, 2023
Question

I'm using NucleoF401RE. The issue is that GPIO Read pin is always SET. There is nothing connected to board. No pull-up resister connected. When i try to debug, HAL_GPIO_ReadPin always returns Pin_Status as SET.

  • January 31, 2023
  • 3 replies
  • 2266 views

Code isn't complex, hence i don't understand what could be the problem.

char pin_status;

pin_status=HAL_GPIO_ReadPin(SENSOR_H1_GPIO_Port,SENSOR_H1_Pin);

0693W00000Y9bP7QAJ.png

This topic has been closed for replies.

3 replies

KnarfB
Super User
January 31, 2023

If there is nothing connected, the pin is floating and the result undetermined, maybe 1 maybe 0.

hth

KnarfB

gbm
Super User
January 31, 2023

There is no problem. If nothing is connected and the pin is not pulled up or high internally, random level is read. Random may be 0 or 1, depending on humidity, air ionization, touching etc. Enable the pull-down to force it to 0 when left open.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
S.Ma
Principal
January 31, 2023

First, read the GPIO HW registers in debug mode, not a variable .

Second, manually turn the GPIO MODER and OUT registers to turn the pin to output low.

Then check the IDR pin level.

If the registers are always zero, the GPIO clock enable is missing

If the input level does not change, the pin is forced by external HW to its level.