2013-02-09 08:05 AM
Hello;
i have problems to understand how to configure an GPIO input port correctly. What i wan't: Port PA5 shall be configured als input port. A simple switch is conected between the +5V source and the input pin. The desired behaviour: Input PA5 is ''high'' when switch is closed Input PA5 is ''low'' when switched is opened i tried to configure the port as follows:.....
GPIOA_InitSTructure.
GPIO_Pin
= GPIO_Pin_5;
GPIOA_InitSTructure.GPIO_Mode
=
GPIO_Mode_IN
;
GPIOA_InitSTructure.GPIO_OType
=
GPIO_OType_PP
;
GPIOA_InitSTructure.GPIO_PuPd
=
GPIO_PuPd_DOWN
;
/*GPIOA_InitSTructure.GPIO_PuPd = GPIO_PuPd_NOPULL*/
;GPIOA_InitSTructure.
GPIO_PuPd
=
GPIO_PuPd_UP
;GPIOA_InitSTructure.
GPIO_Speed
=
GPIO_Speed_50MHz
; GPIO_Init(GPIOA, &GPIOA_InitSTructure); The problem: The Port is always high, even when the switch is open or not connected to Port .I tried all 3 combinations: PullUp, Pull Down,NoPull What wen't wrong and how to configure the ports correctly ? I am using a Waveshare Open407Z Board with STM32F407ZGT6 Processor Thanks in advance. Marc2013-02-09 09:00 AM
Why 5V, wouldn't the 3-3.3V supply the part is running off be more appropriate.
Perhaps then problem is the code you're not showing, always helps to provide a complete context. If you don't enable the clock you won't be able to program the peripheral. Look at the register settings in a debugger.void TestPA5(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_Init(GPIOA, &GPIO_InitStructure);
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5) != RESET)
puts(''High'');
else
puts(''Low'');
}
2013-02-09 11:42 AM
Hello;
Yes of course: I have enabled the clock first, thats not the problem
I also used the 3.3 V Supply at the header but the behaviour is the same.
I think it depends on the hardware design of the Button Interface on the board.
I have noticed at least one pullup resitor in the schematic drawing.
I will try another input port and check again.
Tank you
2013-02-09 01:33 PM
GPIOA_InitSTructure.
GPIO_PuPd
=
GPIO_PuPd_DOWN
;
/*GPIOA_InitSTructure.GPIO_PuPd = GPIO_PuPd_NOPULL*/
;
GPIOA_InitSTructure.
GPIO_PuPd
=
GPIO_PuPd_UP
;So you set it to pull-down, then immediately overwrite that with pull-UP - so of course it will always be high!
2013-02-09 05:01 PM
Yes of course: I have enabled the clock first, thats not the problem
If I got a dollar for everyone who didn't.... I can only work with the information presented. I'd check for external drivers. Do you have a schematic you can attach or link too, nothing is dropping out with a quick search.2013-02-10 07:05 AM
''can only work with the information presented.''
And, according to the information presented, he has the switch configured to switch to +V, and also has a pull-up enabled - so the inputwill
always be highirrespective
of the state of the switch!
To put it another way, the only effect of the switch is to make a ''stronger'' pullup!
2013-02-10 07:48 AM
The Port is always high, even when the switch is open or not connected to Port .I tried all 3 combinations: PullUp, Pull Down,NoPull
Andrew, I'm assuming Marc has tried a number of things before getting here, the slap dash paste job might be a results of that, and why I pasted what I thought was a correct and complete configuration. If that doesn't work, then looking at the attached circuitry is in order. Personally I would have switched to ground, and used a pull-up. The 50K internal, or whatever the poly gets you in this process, should suffice for the test here.2013-02-10 12:54 PM
Well, as you say, all we have to go on is what's posted.
Time for the OP to clarify what's really going on...