AnsweredAssumed Answered

STM32F072CB EXTI

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
#define EC10E_ENCODER_IRQ_DISABLE()\
{\
    NVIC_DisableIRQ(EXTI4_15_IRQn);\
}
 
 
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
    PENC_A->PUPDR &= ~(GPIO_PUPDR_PUPDR14 | GPIO_PUPDR_PUPDR15);
    PENC_A->PUPDR |=  (GPIO_PUPDR_PUPDR14_0 | GPIO_PUPDR_PUPDR15_0);
 
    //3. Clear bits 11:8 and 15:12 and set 0 in the SYSCFG_EXTICR[4] reg to amp EXTI Line to NVIC
    //ENC_A:
    SYSCFG->EXTICR[4] &= (uint16_t)~(SYSCFG_EXTICR4_EXTI14 | SYSCFG_EXTICR4_EXTI15);
    SYSCFG->EXTICR[4] |= (uint16_t) (SYSCFG_EXTICR4_EXTI14_PC | SYSCFG_EXTICR4_EXTI15_PC);
 
    //4. Set interrupt trigger to falling edge on the EXTI1 line
    EXTI->FTSR |= (EXTI_FTSR_TR14 | EXTI_FTSR_TR15);
    EXTI->RTSR &= ~(EXTI_RTSR_TR14 | EXTI_RTSR_TR15);
 
    //5. Unmask EXTI0 line
    EXTI->IMR |= (EXTI_IMR_MR14 | EXTI_IMR_MR15);
        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)
    EC10E_ENCODER_IRQ_ENABLE();
}
 
/// @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.
        EC10E_ENCODER_IRQ_DISABLE();
 
        EXTI->PR |= EXTI_PR_PR14;
    }else
 
    if ((EXTI->IMR & EXTI_IMR_MR15) && (EXTI->PR & EXTI_PR_PR15))
    {
        EC10E_ENCODER_IRQ_DISABLE();
 
        EXTI->PR |= EXTI_PR_PR15;
    }
}
//-----------

Thank you!

Outcomes