Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] Reading input button on PC0 GPIO at STM32 ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Guys,

How can I read a button from GPIO PC0 ?
I have created :


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 ?
thanks
 
Last edited by a moderator:

hi , u config the PC0 in "input pull down mode",so when you dont press the button , the level is always IO low (0), but if u press t button(if the button cennected GND) , the IO level is also low. i think you should make the 4th row " GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; " replce " GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; ". GPIO_Mode_IPD >>>> GPIO_Mode_IPD !!!
 

how can I wait for input from button0 ? PC0 ? so if user hasn't pressed the button, software will stop and wait... ?
 

please upload ur whole codes here . u can write a "while loop or a for loop" to wait for input from button0, and External interrupt as well .
 

where will I put the "while" loop ? thanks
Code:
		 button1 = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0);
	
			 if (button1 == RESET)
		//if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0) == 0x00) 
			  {
			     lcd_cmd(LCD_CLEAR);
				 lcd_string("Button 1 is pressed..");
			     vTaskDelay(2000);
			  }
 

loop this part " if (button1 == RESET)
//if (GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_0) == 0x00)
{
lcd_cmd(LCD_CLEAR);
lcd_string("Button 1 is pressed..");
vTaskDelay(2000);
}"
 

like this :
Code:
while (button1 != RESET )
{
if (button1 == RESET)
{
lcd_cmd(LCD_CLEAR);
lcd_string("Button 1 is pressed..");
vTaskDelay(2000);
}
}

?
Thanks
 

no , add my qq account , add i give u a voice call there , and tell you how to modify the code ...its not convinient to type . and my qq account is :790912166.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top