2019-07-07 11:30 PM
Hey, I have an STM32F4 discovery board which have a user button on it. I am setting button pin as input and when I try pull-down, it works as it should be,
HIGH when pressed
LOW when not pressed
But if I do not know wrong, when I choose pull-up then it should be
LOW when pressed
HIGH when not pressed
But this code below, gives me an always ON led , whether i am pressing or not.
if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0))
HAL_GPIO_WritePin(GPIOD, LD4_Pin, 1);
else
HAL_GPIO_WritePin(GPIOD, LD4_Pin, 0);
Thanks in advance.
Solved! Go to Solution.
2019-07-08 01:43 AM
"If it is not working, then why is unpressed button resulting in a HIGH output ? ( When the button is configured as pull-up )"
Because the button is configured as pull-up (you answered on self question).
When button pressed it shorts with VCC. Check board schematic))
"Also in CubeMX, why ST gives me opportunity to choose pull-up then ?"
CubeMX give you opportunity to choose all functions, this don`t depend from board.
Special for you:
2019-07-08 12:38 AM
Hi. STM32F4-Discovery have a pull-down resistor (R39 220 KOhm) on board. Page 31 of user manual. Typical in-chip pull-up resistor is 40 KOhm. In this case voltage with unpressed button is 2.53 V (logic one).
2019-07-08 12:43 AM
Hey, thanks for the answer. But I am also saying that it should be and it is HIGH with unpressed button. My problem is with pressed button case at pull-up configuration.
2019-07-08 01:02 AM
Pull-up configuration dont work with this board. Because when button pressed pin state is high. Check board schematic.
2019-07-08 01:21 AM
If it is not working, then why is unpressed button resulting in a HIGH output ? ( When the button is configured as pull-up )
Also in CubeMX, why ST gives me opportunity to choose pull-up then ?
Thanks anyway.
2019-07-08 01:43 AM
"If it is not working, then why is unpressed button resulting in a HIGH output ? ( When the button is configured as pull-up )"
Because the button is configured as pull-up (you answered on self question).
When button pressed it shorts with VCC. Check board schematic))
"Also in CubeMX, why ST gives me opportunity to choose pull-up then ?"
CubeMX give you opportunity to choose all functions, this don`t depend from board.
Special for you:
2019-07-08 02:22 AM
Hey, thank you so much.
With your last eddition of that figure, now I understand it. At first I thought that R39 220K is the pull-down resistor. Which is not according to your figure.