AnsweredAssumed Answered

STM32L151 Interrupt Problem

Question asked by kiran.adithya on Apr 10, 2013
Latest reply on Aug 21, 2016 by Clive One
Hi,

I am using the STM32L151VB on  a custom board. The MCU is clocked by HSI.
I have two rising edge interrupts on port E pin 9 and port E pin 10. I capture the timer counter for timer 4 in both the interrupts. The problem is that for each rising edge I am getting multiple interrupts and hence wrong values of timer 4 are captured. If I can ensure that only one interrupt per rising edge is generated it will solve my problem. Also my pulses have varying widths so using delay is not possible. Please advise. I have pasted my code below:


void WS_Init_Wind_Sensors_Input()
{
  GPIO_InitTypeDef gpio_init_structure;
  EXTI_InitTypeDef exti_init ;
 
  /* Enable GPIO clocks */
  RCC_AHBPeriphClockCmd(WIND_SPEED_SENSOR_RCC_AHBPeriph | WIND_DIRECTION_SENSOR_RCC_AHBPeriph, ENABLE);
 
  gpio_init_structure.GPIO_Pin  = WIND_SPEED_SENSOR_GPIO_PIN;
  gpio_init_structure.GPIO_Mode = GPIO_Mode_IN;
  gpio_init_structure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  gpio_init_structure.GPIO_Speed = GPIO_Speed_40MHz;
  gpio_init_structure.GPIO_OType = GPIO_OType_PP;
 
  /* Initialise the GPIO accordingly */
  GPIO_Init(WIND_SPEED_SENSOR_GPIO_PORT, &gpio_init_structure);
 
  gpio_init_structure.GPIO_Pin  = WIND_DIRECTION_SENSOR_GPIO_PIN;
 
  /* Initialise the GPIO accordingly */
  GPIO_Init(WIND_DIRECTION_SENSOR_GPIO_PORT, &gpio_init_structure);
 
  /* The syscfg module is clocked */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
 
  /* The EXTI mux is on exti line RG_EXTI_PINSOURCE for this GPIO pin */
  SYSCFG_EXTILineConfig(WIND_SPEED_SENSOR_EXTI_PortSource,WIND_SPEED_SENSOR_EXTI_PinSource);
 
  /* The EXTI mux is on exti line RG_EXTI_PINSOURCE for this GPIO pin */
  SYSCFG_EXTILineConfig(WIND_DIRECTION_SENSOR_EXTI_PortSource,WIND_DIRECTION_SENSOR_EXTI_PinSource);
 
  EXTI_StructInit(&exti_init);
  exti_init.EXTI_Line = WIND_SPEED_SENSOR_EXTI_LINEx;
  exti_init.EXTI_LineCmd = ENABLE;
  exti_init.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_Init(&exti_init);
 
   /*Enable the interrupt in the NVIC */
  INIT_NVIC_Enable_Peripheral_Interrupt(WIND_SPEED_SENSOR_EXTIx_IRQn,0,0);
 
  exti_init.EXTI_Line = WIND_DIRECTION_SENSOR_EXTI_LINEx;
  exti_init.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_Init(&exti_init);
  /*Enable the interrupt in the NVIC */
  INIT_NVIC_Enable_Peripheral_Interrupt(WIND_DIRECTION_SENSOR_EXTIx_IRQn,2,2);
 
}
 
int td1x, ts1x, ts2x ;
 
/*!
    Interrupt handler for pulse 1
     
*/
void EXTI9_5_IRQHandler(void)
{
    INIT_NVIC_Disable_Peripheral_Interrupt(WIND_DIRECTION_SENSOR_EXTIx_IRQn,0,0);
     
    EXTI->PR = EXTI_Line9 ;
     
    /* This is being set multiple times for each rising edge since the interrupt is being re-entrant */
    td1x = TIM4->CNT;
     
    INIT_NVIC_Enable_Peripheral_Interrupt(WIND_DIRECTION_SENSOR_EXTIx_IRQn,0,0);
}
     
 
/*!
    Interrupt handler for pulse 2
     
*/
void EXTI15_10_IRQHandler()
{
    static int x = 1;
     
    INIT_NVIC_Disable_Peripheral_Interrupt(WIND_SPEED_SENSOR_EXTIx_IRQn,0,0);
         
    EXTI->PR = EXTI_Line10;
     
    /* This is being set multiple times for each rising edge since the interrupt is being re-entrant */
    x ^= 1;
     
    if(x)
    {
        ts2x = TIM4->CNT;
    }
    else
    {
         ts1x = TIM4->CNT;
    }
     
    INIT_NVIC_Enable_Peripheral_Interrupt(WIND_SPEED_SENSOR_EXTIx_IRQn,0,0);
}

Outcomes