AnsweredAssumed Answered

the mcu stuck with external interrupt

Question asked by cirillo.andrea on Aug 30, 2012
Latest reply on Sep 2, 2012 by fm
Hello, sorry for my bad English. I'm developing an application for a STM32F103ZE that reads the value from three sensor via I2C bus, use the SysTick timer, use USART1 to communicate with the pc, generates four pwm signal with TIM3, use TIM2 to measure the width of four pulse that generates on rising and falling edge an interrupt. If I disable the external interrupt the fw works well but if I enable it the mcu stop the software execution after some seconds.
This is the Interrupt configuration:
void EXTI_Conf(void)
 {
     EXTI_InitTypeDef EXTI_InitStructure;
     GPIO_InitTypeDef GPIO_InitStructure;
     NVIC_InitTypeDef NVIC_InitStructure;
  
   // Enable GPIOD clock
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
  
   // Configure PD8-12 pins as input floating
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOD, &GPIO_InitStructure);
  
   // Enable AFIO clock 
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  
   // Connect EXTI Lines to PD8-12 pins
   GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource8);
   GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource9);
   GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource10);
   GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource11);
   GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource12);
  
   // Configure EXTI lines
   // PD8-11 Get Counter;
   EXTI_InitStructure.EXTI_Line = EXTI_Line8;
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   EXTI_Init(&EXTI_InitStructure);
  
   EXTI_InitStructure.EXTI_Line = EXTI_Line9;
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   EXTI_Init(&EXTI_InitStructure);
  
   EXTI_InitStructure.EXTI_Line = EXTI_Line10;
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   EXTI_Init(&EXTI_InitStructure);
  
   EXTI_InitStructure.EXTI_Line = EXTI_Line11;
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   EXTI_Init(&EXTI_InitStructure);
  
   // PD12 Get Counter, calculate, reset timer2
   EXTI_InitStructure.EXTI_Line = EXTI_Line12;
   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 EXTI9_5 Interrupt to the lowest priority
   NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);
  
   // Enable and set EXTI15_10 Interrupt to the lowest+1 priority
   NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);
 }
And this is the interrupt ISR:
void EXTI9_5_IRQHandler(void)
{
    if(EXTI_GetITStatus(EXTI_Line8) != RESET)
    {
        tGetCnt[0] = TIM2->CNT;   
        EXTI_ClearITPendingBit(EXTI_Line8); 
    }
    else if(EXTI_GetITStatus(EXTI_Line9) != RESET)
    {
        tGetCnt[1] = TIM2->CNT;    
        EXTI_ClearITPendingBit(EXTI_Line9);     
    }
    else while(1);
}
void EXTI15_10_IRQHandler(void)
{
    if(EXTI_GetITStatus(EXTI_Line10) != RESET)
    {
        tGetCnt[2] = TIM2->CNT; 
        EXTI_ClearITPendingBit(EXTI_Line10);    
    }
    else if(EXTI_GetITStatus(EXTI_Line11) != RESET)
    {
        tGetCnt[3] = TIM2->CNT;
        EXTI_ClearITPendingBit(EXTI_Line11);    
    }
    else if(EXTI_GetITStatus(EXTI_Line12) != RESET)
    {
        tGetCnt[4] = TIM2->CNT;
          
        if (tGetCnt[4] != 0)
        {
           inputCommand[0] = tGetCnt[0];
           inputCommand[1] = tGetCnt[1] - inputCommand[0];
           inputCommand[2] = tGetCnt[2] - inputCommand[0] - inputCommand[1];
           inputCommand[3] = tGetCnt[3] - inputCommand[0] - inputCommand[1] - inputCommand[2];  
        }
        else
        {
           printf("Errore...\r\n");
        }                  
          
        TIM_SetCounter(TIM2, 0);
          
        EXTI_ClearITPendingBit(EXTI_Line12);
    }
    else while(1);
}
Thank you for any suggestions.

Outcomes