STM32F401RE-Nucleo LED and BUTTON's problem
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-04-07 9:27 AM
Posted on April 07, 2015 at 18:27
Hi,
I am trying to run a simple program on my new Nucleo board,
I made this program in order to turn on and off the green led when i press the user's button (the blue one),
#include ''stm32f4xx.h''
#include ''stm32f4xx_nucleo.h''
#include ''system_stm32f4xx.h''
#include ''stm32f4xx_hal_gpio.h''
#include ''stm32f4xx_hal_rcc.h''
GPIO_InitTypeDef GPIO_InitStructure;
int
main(
void
) {
HAL_Init();
__GPIOA_CLK_ENABLE();
GPIO_InitStructure.Pin = GPIO_PIN_5;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
__GPIOC_CLK_ENABLE();
GPIO_InitStructure.Pin = GPIO_PIN_13;
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLDOWN;
GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
while
(1) {
if
(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
}
else
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_SET);
}
}
}
But i am getting wrong result:
- when i press the user's button, nothing happen,
- when i keep pressing the user's button and i restart (by pressing the black button), i get good result,
It seems like the program checks the state of the blue button only at the first run, i don't know why,
Please help me if you have any ideas of what the problem comes from, or if you have a running program that switch the led on button press.
Thank you,
#stm32f401re
Labels:
- Labels:
-
STM32F4 Series
This discussion is locked. Please start a new topic to ask your question.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2015-04-07 10:19 PM
Posted on April 08, 2015 at 07:19
Hi samy,
do you have system clock configuration in your program?