cancel
Showing results for 
Search instead for 
Did you mean: 

GPIO interrupt problem

freya17365
Associate II
Posted on June 07, 2016 at 20:46

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

1 REPLY 1
Posted on June 07, 2016 at 22:47

Which STM32 are we talking about?

Isn't the EXTICR value of 8 for PI, not PA, at least on the F2/F4 parts

The SYSCFG peripheral clock would normally need enabling

PA13,PA14 are typically used for debugging, going to make it harder to debug

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..