This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

About interrupt

Hi
I am trying to use EXTI interrupt which should toggle an led but program stops in an endless loop when I use the following code.
I am using STM32L1 discovery board. I had the same problem when using TIM2 interrupt too.
a part of my code is:

EXTI_InitTypeDef   EXTI_InitStructure;

        void EXTILine0_Config(void);

        void ExtInt(void)
        {

          /* Configure EXTI Line0 (connected to PA0 pin) in interrupt mode */
          EXTILine0_Config();

          /* Generate software interrupt: simulate a rising edge applied on EXTI0 line */
          EXTI_GenerateSWInterrupt(EXTI_Line0);
        }


        void EXTILine0_Config(void)
        {

          GPIO_InitTypeDef   GPIO_InitStructure;
          NVIC_InitTypeDef   NVIC_InitStructure;

          /* Enable GPIOA clock */
          RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
          /* Enable SYSCFG clock */
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

          /* Configure PA0 pin as input floating */
          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
          GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
          GPIO_Init(GPIOA, &GPIO_InitStructure);

          /* Connect EXTI Line0 to PA0 pin */
          SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

          /* Configure EXTI Line0 */
          EXTI_InitStructure.EXTI_Line = EXTI_Line0;
          EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
          EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
          EXTI_InitStructure.EXTI_LineCmd = ENABLE;
          EXTI_Init(&EXTI_InitStructure);

          /* Enable and set EXTI Line0 Interrupt to the lowest priority */
          NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
          NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
          NVIC_Init(&NVIC_InitStructure);
        }

        /**
          * @brief  This function handles External line 0 interrupt request.
          * @param  None
          * @retval None
          */
        void EXTI0_IRQHandler(void)
        {
          if(EXTI_GetITStatus(EXTI_Line0) != RESET)
          {
            /* Toggle LED1 */
            GPIO_ToggleBits(GPIOB, LED_Blue);

            /* Clear the EXTI line 0 pending bit */
            EXTI_ClearITPendingBit(EXTI_Line0);
          }
        }

main(){
ExtInt();
while(1)
{
GPIO_ToggleBits(GPIOB,LED_Green);//GPIO_ToggleBits(GPIOB,LED_Blue);
for(i=0;i<200000;i++){ };
}
}

Parents
  • The problem solved after I removed the file below which I had written it for timer interrupt

    void Init_NVIC(void)
    {
    NVIC_InitTypeDef NVIC_InitStructure;
     //NVIC_SETPRIMASK();
      // NVIC init
    #ifndef  EMB_FLASH
      /* Set the Vector Table base location at 0x20000000 */
      NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
    #else  /* VECT_TAB_FLASH  */
      /* Set the Vector Table base location at 0x08000000 */
      NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
    #endif
      NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
            NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure);
    
            NVIC_EnableIRQ(TIM2_IRQn);
            TIM2->DIER = TIM_DIER_UIE;
    }
    

    I modified it like below:

         NVIC_InitTypeDef   NVIC_InitStructure;
    
              NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
              NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
              NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
              NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
              NVIC_Init(&NVIC_InitStructure);
    
            // Clear update interrupt bit
      TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
      // Enable update interrupt
      TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
    

Reply
  • The problem solved after I removed the file below which I had written it for timer interrupt

    void Init_NVIC(void)
    {
    NVIC_InitTypeDef NVIC_InitStructure;
     //NVIC_SETPRIMASK();
      // NVIC init
    #ifndef  EMB_FLASH
      /* Set the Vector Table base location at 0x20000000 */
      NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
    #else  /* VECT_TAB_FLASH  */
      /* Set the Vector Table base location at 0x08000000 */
      NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
    #endif
      NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
            NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure);
    
            NVIC_EnableIRQ(TIM2_IRQn);
            TIM2->DIER = TIM_DIER_UIE;
    }
    

    I modified it like below:

         NVIC_InitTypeDef   NVIC_InitStructure;
    
              NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
              NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
              NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
              NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
              NVIC_Init(&NVIC_InitStructure);
    
            // Clear update interrupt bit
      TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
      // Enable update interrupt
      TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
    

Children
No data