cancel
Showing results for 
Search instead for 
Did you mean: 

User button

achourwissem
Associate II
Posted on August 19, 2013 at 12:18

hello

i'm trying to make the user button working with a simple led program here is the code and please tell me what's the problem (it worked just when i keep pushing user button then make a reset):

******************

#include ''stm32f4xx.h''

#include ''stm32f4_discovery.c''

#include ''stm32f4xx_gpio.c''

#include ''stm32f4xx_rcc.c''

#include ''stm32f4xx_tim.c''

#include ''misc.c''

#include ''stm32f4xx_syscfg.c''

#include ''stm32f4xx_exti.c''

#include ''wissem.c''

int main(void)

{

 GPIO_InitTypeDef  GPIO_InitStructure;

/* GPIOD Periph clock enable */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

  /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

while(1){

 

if(STM_EVAL_PBGetState(BUTTON_USER) == Bit_SET )

      {           

        

GPIO_WriteBit(GPIOD,GPIO_Pin_12,1); //ecrire le bit

delay_ms(1000);

GPIO_WriteBit(GPIOD,GPIO_Pin_12,0); //ecrire le bit

delay_ms(1000);

      }

   

STM_EVAL_PBGetState(BUTTON_USER);

       

    }

  }

 

   

2 REPLIES 2
Posted on August 19, 2013 at 14:10

You have an EXTI interrupt handler?

If not the use

STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
achourwissem
Associate II
Posted on August 20, 2013 at 10:56

thank you it worked now u were right i miss that EXTI interrupt handler