AnsweredAssumed Answered

GPIO interrupt problem

Question asked by Laga.Freya on Jun 7, 2016
Latest reply on Jun 7, 2016 by Clive One
Hi to all,
I got a problem with GPIO interrupt.
I have two buttons connected to pin 13 and 14 of port A.
I configured pins in input and enabled interrupt, then I wrote the interrupt routine.
When I pushed a button I got an interrupt, but I am not able to determine which button is pressed.
EXTI->PR gives always 0x6000
GPIOA->IDR gives 0xF00 or 0xE00 for both buttons.

How can I distinguish the buttons?

Here is my code:

====================================================
#define BUT0        13        //GPIOA
#define BUT1        14        //GPIOA

MYBUTTON::MYBUTTON()
{
    if(!(RCC->AHBENR & RCC_AHBENR_GPIOAEN)) RCC->AHBENR |= RCC_AHBENR_GPIOAEN;        // Enable GPIOA clock    
    
    GPIOA->MODER &= ~(0x03U<<(2*BUT0) | 0x03U<<(2*BUT1));    //Mode function: 00=input; 01=output; 10=alternate; 11=analog
    GPIOA->MODER |= 0x00<<(2*BUT0) | 0x00<<(2*BUT1);
    GPIOA->OSPEEDR &= ~(0x03U<<(2*BUT0) | 0x03U<<(2*BUT1));    //Pin speed = low speed
    GPIOA->OSPEEDR |= 0x00<<(2*BUT0) | 0x00<<(2*BUT1);
    GPIOA->PUPDR &= ~(0x03U<<(2*BUT0) | 0x03U<<(2*BUT1));    //Pull up: 00=No pll up/down; 01=pull up; 10=pull down
    GPIOA->PUPDR |= 0x01<<(2*BUT0) | 0x01<<(2*BUT1);
    
    /* Interrupt configuration */
    SYSCFG->EXTICR[3] |= 0x00000880;    // Pin 13 and 14 of GPIOA
    EXTI->IMR |= 1L<<BUT0 | 1L<<BUT1;    // Interrupt MASK
    EXTI->FTSR |= 1L<<BUT0 | 1L<<BUT1;    // Falling trigger
    
}


and the interrup routine:

extern "C" void EXTI4_15_IRQHandler()
{
    uint32_t a,b,c;
    
    a=EXTI->PR;
    b=EXTI->EMR;
    c=GPIOA->IDR;
    
    myusart1.PrintString((uint8_t *) "BUTTON INTERRUPT", ' ', 0);
    myusart1.PrintHex(a, ' ');
    myusart1.PrintHex(b, ' ');
    myusart1.PrintHex(c, '\n');
    EXTI->PR |= 1L<<BUT0 | 1L<<BUT1;    // Reset interrupt status register
    return;
}

====================================================


Thank you
Freya


Outcomes