AnsweredAssumed Answered


Question asked by nagy.attila on Apr 29, 2015
Latest reply on Apr 30, 2015 by nagy.attila
Hi all,

I have a problem again.
We using STM32F072CB LQFP48 controller in a project where we connected an encoder to PC14 and PC15. We don't use external clock source.
So I enabled GPIO clock for GPIOC, set PC14 and PC15 as input with Pull-Up, set EXTI4->EXIT14 and EXTI15 to GPIOC and enable interrupt.

My problem is the EXTI4_15 interrupt handler receives interrupt continuously and I don't understand why.

Here is the code snipet:
#define ENC_A           GPIO_Pin_15
#define ENC_B           GPIO_Pin_14
#define PENC_A          GPIOC
#define pENC_A          GPIOC, ENC_A
#define pENC_B          GPIOC, ENC_B
void Ec10e_encoder_Init(void)
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
    //1. Configure the GPIO as input
    //Init_GPIO_Mode(pENC_A | ENC_B, GPIO_Mode_IN);
    GPIO_InitTypeDef InitGpio;
    InitGpio.GPIO_Pin = ENC_A | ENC_B;
    InitGpio.GPIO_Mode = GPIO_Mode_IN;
    InitGpio.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(PENC_A, &InitGpio);
    //2. Ensure pull up resistor is enabled, pull down resistor is disabled
    //   is connected to Pushbutton
    //3. Clear bits 11:8 and 15:12 and set 0 in the SYSCFG_EXTICR[4] reg to amp EXTI Line to NVIC
    //4. Set interrupt trigger to falling edge on the EXTI1 line
    //5. Unmask EXTI0 line
        EXTI->EMR &= ~(EXTI_IMR_MR14 | EXTI_IMR_MR15);
    //6. Set Priority to 3
    NVIC_SetPriority(EXTI4_15_IRQn, 3);
    //7. Enable EXTI4_15 interrupt in NVIC (do 4 first)
/// @brief  EXTI_4_15_IRQHandler for encoder (ENC_A, ENC_B; GPIO_Pin_15, GPIO_Pin_14; PC15, PC14).
/// @param  None
/// @retval None
void EXTI4_15_IRQHandler(void)
    if ((EXTI->IMR & EXTI_IMR_MR14) && (EXTI->PR & EXTI_PR_PR14))
               //I always receive this interrupt even if the encoder is in stable state.
        EXTI->PR |= EXTI_PR_PR14;
    if ((EXTI->IMR & EXTI_IMR_MR15) && (EXTI->PR & EXTI_PR_PR15))
        EXTI->PR |= EXTI_PR_PR15;

Thank you!