2014-12-30 05:15 AM
Guys,
How can I read a button from GPIO PC0 ? I have created : RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOA, ENABLE); //initialize PC0 and PC1 as button input GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // this sets up input to be used with external push up/pull down resistors. GPIO_Init(GPIOC, &GPIO_InitStructure); . .. .. .. uint8_t button1; button1 = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0); if (button1 == 0x00) { lcd_string(''Button 1 is pressed..''); } any opinions ? thanks2014-01-01 03:14 PM
2014-01-01 03:45 PM
May be it would be helpful if you described the physical wiring of your button, and why the internal pull down?
2014-01-02 01:11 AM
2014-01-02 02:49 AM
2014-01-02 04:55 AM
If the push button is a connected between PC0 and ground then you need a pull up resistor, either internally or externally. You have configured an internal pull down resistor on PC0 so I suspect that you need to configure this as pull up (assuming no external pull up or down resistors connected to PC0 externally).
2014-01-03 06:06 AM
2014-01-03 08:08 AM
Like this (maybe). Note: this will keep writing to the LCD while the button is pressed but I have no way of knowing what else you might want it to do:
for (;;)
{
if (!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0))
{
lcd_cmd(LCD_CLEAR);
lcd_string(''Button 1 is pressed..'');
vTaskDelay(2000);
}
}
And this does not cater for any ''de-bouncing'' that might be required.
2014-01-04 03:04 AM
It doesn't give a response to a push button...any clues ?
2014-01-04 04:24 AM
You need to provide us with the ''clues'' as you are the only one that use a debugger with the actual hardware. E.g. what happens when you single step into GPIO_ReadInputDataBit ? Check the pin with a multimeter or scope to see that it goes low when switch is pressed and is high when the switch is not pressed. Check configuration registers against the data sheet and confirm with the debugger that they are getting set to what is expected. Make a small (small as possible) example and provide it all to us - otherwise we have to get our crystal ball out and mine is very dusty at the moment ;-).