Why led isn't blinking when i press the button?
I am tring to write a code for stm32f401cb which will blink the led when i press the led and when i leave pressing the button,it will turn out the led.I have set channel ahb1 which connects to port a and b in my microprocessor f401cb and i chose input type pull down in port a and led is connected to port b.
But my led is not blinking in anyway.
where is my mistake you think?
My led is not blinking when i press the button.it is always turned out
As you can see in the picture am holding the button but there is no response on the led.
Note:Port a is selected as input and port b is selected as output and both ports are controlled with their 0 (zero) pins.
my code is like that
Why i cant get a response on the led?
#include "stm32f4xx.h"
void ahb1_config(void) {
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE);
}
void gpio_config(void) {
GPIO_InitTypeDef gpio_init;
gpio_init.GPIO_Mode=0x00;
gpio_init.GPIO_Pin=GPIO_Pin_0 ;
gpio_init.GPIO_OType=0x00;
gpio_init.GPIO_PuPd=0x02;
gpio_init.GPIO_Speed=0x03;
GPIO_Init(GPIOA,&gpio_init);
gpio_init.GPIO_Mode=GPIO_Mode_OUT;
gpio_init.GPIO_Pin=GPIO_Pin_0 ;
gpio_init.GPIO_OType=GPIO_OType_PP;
gpio_init.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOB,&gpio_init);
}
int main(void)
{
while (1)
{
ahb1_config();
gpio_config();
if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)) {
GPIO_SetBits(GPIOB,GPIO_Pin_0);
}
else {
GPIO_ToggleBits(GPIOB,GPIO_Pin_0);
}
}
}
