[SOLVED] GPIO Interrupt problem

Discuss how to use the features of Atollic TrueSTUDIO, including the editor, assembler, C/C++ compiler, linker, debugger, static code analysis and team collaboration tools.

Moderators: Markus Girdland, Mattias Norlander

TRGercek
Posts: 1
Joined: Thu Jan 31, 2019 5:39 pm

[SOLVED] GPIO Interrupt problem

Postby TRGercek » Thu Jan 31, 2019 5:52 pm

HI everyone

I am working on GPIO ınterrupt. In main file, LED's are toggling,my goal is when I push the button, LED's go to RESET immediately and after reset,LED's keep on toggling in main file.

Everything works fine.LED's are toogling until I push button. When I push button,LED's stop and do nothing.Where is the problem I dont understand.

Is there anyone knows this problem or who can solve it.Please help.

Best regards.

Gercek

Code: Select all

#include "stm32f4xx.h"
#include "stm32f4_discovery.h"


   GPIO_InitTypeDef LED;
   GPIO_InitTypeDef Button1;

   EXTI_InitTypeDef EXT_INT;  //external interrupt icin structer
   NVIC_InitTypeDef NVICsruct;

   int butonstatus;
   void delay(uint32_t time){

      while(time--){

      }

   }

   void config(){

   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);

   //LED
   LED.GPIO_Mode=GPIO_Mode_OUT;
   LED.GPIO_OType=GPIO_OType_PP;
   LED.GPIO_Pin=GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
   LED.GPIO_PuPd=GPIO_PuPd_NOPULL;
   LED.GPIO_Speed=   GPIO_Speed_100MHz;

   GPIO_Init(GPIOD,&LED);

       Button1.GPIO_Mode=GPIO_Mode_IN;
       Button1.GPIO_Pin=GPIO_Pin_0;
       Button1.GPIO_OType=GPIO_OType_PP;
       Button1.GPIO_PuPd=GPIO_PuPd_DOWN;
       Button1.GPIO_Speed=GPIO_Speed_100MHz;

       GPIO_Init(GPIOA,&Button1);


       SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0); // Butona interrupt eklendi
       EXT_INT.EXTI_Line=EXTI_Line0;
       EXT_INT.EXTI_LineCmd=ENABLE;
       EXT_INT.EXTI_Mode=EXTI_Mode_Interrupt;
       EXT_INT.EXTI_Trigger=EXTI_Trigger_Rising;

       EXTI_Init(&EXT_INT);


       NVICsruct.NVIC_IRQChannel=EXTI0_IRQn;
       NVICsruct.NVIC_IRQChannelCmd=ENABLE;
       NVICsruct.NVIC_IRQChannelPreemptionPriority=0xFF;    //INTERRUPT'ların öncelik sırası ile ilgili
       NVICsruct.NVIC_IRQChannelSubPriority=0x00;         //

       NVIC_Init(&NVICsruct);

}


   void EXTI0_IRQHandler(void);

int main(void)
{
   config();
   GPIO_ResetBits(GPIOD,GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
  while (1)
  {

             GPIO_SetBits(GPIOD,GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_12);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_13);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_14);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_15);
             EXTI0_IRQHandler();

  }
}

void EXTI0_IRQHandler(void) // İnterruptın gideceği fonksiyona HANDLER deniir.

      {   butonstatus=EXTI_GetFlagStatus(EXTI_Line0);

         if (butonstatus!=RESET)
         {
         GPIO_ResetBits(GPIOD,GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);

         EXTI_ClearITPendingBit(EXTI_Line0);   //INTRERRUPT Bayrağı kalktıktan sonra , tekrar fonksiyona dönmesini sağlamak için
                                    //INTERRUPTı sıfırladık

         //EXTI_ClearFlag(EXTI_Line0);

         }


      }


/*
 * Callback used by stm32f4_discovery_audio_codec.c.
 * Refer to stm32f4_discovery_audio_codec.h for more info.
 */
extern "C" void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size){
  /* TODO, implement your code here */
  return;
}

/*
 * Callback used by stm324xg_eval_audio_codec.c.
 * Refer to stm324xg_eval_audio_codec.h for more info.
 */
extern "C" uint16_t EVAL_AUDIO_GetSampleCallBack(void){
  /* TODO, implement your code here */
  return -1;
}



SOLVE:
IF You use atollic TrueStudio in c++ language,To avoid the above problem use extern "C" in block for Handler function.

The correct code is below, check Handler function!



Code: Select all

#include "stm32f4xx.h"
#include "stm32f4_discovery.h"


   GPIO_InitTypeDef LED;
   GPIO_InitTypeDef Button1;

   EXTI_InitTypeDef KESME;  //external interrupt icin structer
   NVIC_InitTypeDef NVICsruct;

   int butonstatus;
   void delay(uint32_t time){

      while(time--){

      }

   }

   void config(){

   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);
   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG,ENABLE);

   //LED
   LED.GPIO_Pin=GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ;
   LED.GPIO_Mode=GPIO_Mode_OUT;
   LED.GPIO_OType=GPIO_OType_PP;
   LED.GPIO_PuPd=GPIO_PuPd_NOPULL;
   LED.GPIO_Speed=   GPIO_Speed_100MHz;

   GPIO_Init(GPIOD,&LED);
       Button1.GPIO_Pin=GPIO_Pin_0;
       Button1.GPIO_Mode=GPIO_Mode_IN;
       Button1.GPIO_OType=GPIO_OType_PP;
       Button1.GPIO_PuPd=GPIO_PuPd_DOWN;
       Button1.GPIO_Speed=GPIO_Speed_100MHz;

       GPIO_Init(GPIOA,&Button1);


       SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0); // Butona interrupt eklendi
       KESME.EXTI_Line=EXTI_Line0;
       KESME.EXTI_LineCmd=ENABLE;
       KESME.EXTI_Mode=EXTI_Mode_Interrupt;
       KESME.EXTI_Trigger=EXTI_Trigger_Rising;

       EXTI_Init(&KESME);


       NVICsruct.NVIC_IRQChannel=EXTI0_IRQn;
       NVICsruct.NVIC_IRQChannelCmd=ENABLE;
       NVICsruct.NVIC_IRQChannelPreemptionPriority=0xFF;    //INTERRUPT'ların öncelik sırası ile ilgili
       NVICsruct.NVIC_IRQChannelSubPriority=0x00;         //

       NVIC_Init(&NVICsruct);

}

   extern "C"{               //      **************   
   void EXTI0_IRQHandler(void);       // WE CHANGED HERE !!!!!
   }                         //           **************
int main(void)
{
   config();
   GPIO_ResetBits(GPIOD,GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);

  while (1)
  {
               EXTI0_IRQHandler();
             GPIO_SetBits(GPIOD,GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_12);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_13);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_14);
             delay(16800000);
             GPIO_ResetBits(GPIOD,GPIO_Pin_15);


  }
}

void EXTI0_IRQHandler(void) // İnterruptın gideceği fonksiyona HANDLER deniir.

      {   butonstatus=EXTI_GetFlagStatus(EXTI_Line0);

         if (butonstatus!=RESET)
         {
         GPIO_ResetBits(GPIOD,GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);

         EXTI_ClearITPendingBit(EXTI_Line0);   //INTRERRUPT Bayrağı kalktıktan sonra , tekrar fonksiyona dönmesini sağlamak için
                                    //INTERRUPTı sıfırladık

         //EXTI_ClearFlag(EXTI_Line0);



      }
      }


/*
 * Callback used by stm32f4_discovery_audio_codec.c.
 * Refer to stm32f4_discovery_audio_codec.h for more info.
 */

extern "C" void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size){
  /* TODO, implement your code here */
  return;
}

/*
 * Callback used by stm324xg_eval_audio_codec.c.
 * Refer to stm324xg_eval_audio_codec.h for more info.
 */
extern "C" uint16_t EVAL_AUDIO_GetSampleCallBack(void){
  /* TODO, implement your code here */
  return -1;
}


Return to “Atollic TrueSTUDIO tool discussions”

Who is online

Users browsing this forum: No registered users and 1 guest