AnsweredAssumed Answered

Problem with external interrupts

Question asked by tuladhar.prateek on Jan 5, 2014
Latest reply on Jan 6, 2014 by tuladhar.prateek
I am trying to attach interrupt to my motor encoder ( connected to pin PB9). My idea is to get the pulse count as the motor rotates. Shown below is a snippet of my code to attach interrupt to pin PB9. I should be getting the pulse count but I don't. Any help would be appreciated. Thanks. 

. void (*exti9_handler)();
pulseCount()
{
     count++;
}
attachInterrupt(pulseCount, CHANGE);          // set pin for encoder pin 


void attachInterrupt(void (*ISR)(void), int mode) 
{
     EXTI_InitTypeDef EXTI_InitStructure;
     NVIC_InitTypeDef NVIC_InitStructure;
     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource9);
                    
     EXTI_StructInit(&EXTI_InitStructure);
     EXTI_InitStructure.EXTI_Line = EXTI_Line9;
     EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
     
     EXTI_InitStructure.EXTI_Trigger =EXTI_Trigger_Rising_Falling;  
     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
     EXTI_Init(&EXTI_InitStructure);
     
     NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);
     exti9_handler=ISR;
}
void EXTI4_15_IRQHandler()
{
     if(EXTI_GetITStatus(EXTI_Line9) != RESET)
        {
               if (exti9_handler != NULL)
           {
                exti9_handler();
           }
      EXTI_ClearITPendingBit(EXTI_Line9);
        }
}

Outcomes