Laga.Freya

STM32F107 EXTI interrupt problem

Discussion created by Laga.Freya on Mar 21, 2017
Latest reply on Mar 26, 2017 by Laga.Freya

Hi to all,
I am using a STM32F107 MCU and I got a problem with EXTI interrupt.
I have 3 buttons connected to PE0, PE1 and PE3. Here I configure them as input

 

#define BUTTON0        0x03        //GPIOE
#define BUTTON1        0x00        //GPIOE
#define BUTTON2        0x01        //GPIOE

 

MYGPIO::MYGPIO()
{
    if(!(RCC->APB2ENR & RCC_APB2ENR_IOPEEN)) RCC->APB2ENR |= RCC_APB2ENR_IOPEEN;        // Enable GPIOE clock
    if(!(RCC->APB2ENR & RCC_APB2ENR_AFIOEN)) RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;        // Enable AFIO clock
    
    GPIOE->CRL &= ~(0x0FUL<<(4*BUTTON0) | 0x0FUL<<(4*BUTTON1) | 0x0FUL<<(4*BUTTON2));    //Resert CRL_MODE and CRL_CNF register
    GPIOE->CRL |= 0x04UL<<(4*BUTTON0) | 0x04UL<<(4*BUTTON1)) | 0x04UL<<(4*BUTTON2);    //Input floating
    AFIO->EXTICR[0] &= ~(AFIO_EXTICR1_EXTI0 | AFIO_EXTICR1_EXTI1 | AFIO_EXTICR1_EXTI3);    // Reset port E pin 0, 1, 3
    AFIO->EXTICR[0] |= AFIO_EXTICR1_EXTI0_PE | AFIO_EXTICR1_EXTI1_PE | AFIO_EXTICR1_EXTI3_PE;    // Set port E pin 0, 1, 3
    EXTI->IMR |= 0x01<<BUTTON0 | 0x01<<BUTTON1 | 0x01<<BUTTON2;
    EXTI->FTSR |= 0x01<<BUTTON0 | 0x01<<BUTTON1 | 0x01<<BUTTON2;
}

 

Here I enable EXTIx interrupt:

 

/* GPIO Interrupt */
NVIC_SetPriority(EXTI0_IRQn, 3);    // Enable GPIO interrupt BUTTON 0
NVIC_EnableIRQ(EXTI0_IRQn);
NVIC_SetPriority(EXTI1_IRQn, 3);    // Enable GPIO interrupt BUTTON 1
NVIC_EnableIRQ(EXTI1_IRQn);
NVIC_SetPriority(EXTI3_IRQn, 3);    // Enable GPIO interrupt BUTTON 2
NVIC_EnableIRQ(EXTI3_IRQn);

 

And here the interrupt routine:

 

extern "C" void EXTI0_IRQHandler()    //the same for EXTI1 and EXTI3
{
    myusart1.PrintString((uint8_t *) "\n\tGPIO INTERRUPT EXTI0", ' ', 0);
    myusart1.PrintHex(EXTI->PR);
    myusart1.PrintChar('\n');
    EXTI->PR |= 0x01<<(BUTTON0 & 0x0F);
    
    return;
}

 


I checked in user manual, in some examples found on internet and it seems everything allright, but I catch no interrupts.
Any suggestions?

 

Thank you Freya

Outcomes