Skip to main content
prateekratna
Associate
January 5, 2014
Question

Problem with external interrupts

Posted on January 05, 2014 at 08:17

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);

    }

}
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    January 5, 2014
    Posted on January 05, 2014 at 14:48

    Is this an STM32F0 device?

    Is the SYSCFG clock enabled?
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    prateekratna
    Associate
    January 6, 2014
    Posted on January 06, 2014 at 13:13

    yes stm32f0.. and yes i configured the clocks..