Interrupt on the XMEGA

cgpio-external-interruptinterruptsxmega

I have 3 buttons connected to PIN1, PIN3, PIN5 of PORTA of an XMEGA. If pushed they deliver a falling edge.
I'm try to generate interrupt using those buttons, I started with one, here is what I have done:

void buttonINT(){
    // PORTA 
    PORTA.PIN1CTRL = PORT_OPC_PULLUP_gc | PORT_ISC_FALLING_gc;
    PORTA.INT0MASK = PIN1_bm;
    PORTA.INTCTRL = PORT_INT0LVL0_bm;
    PMIC.CTRL = PMIC_LOLVLEN_bm;
    sei();
    }
ISR(PORTA_INT0_vect){
    printf(" INTERRUPT \n");
}

in the main I call buttonINT() once , but I get the message all time printed?

Any idea what I'm doing wrong here?

Best Answer

You need to clear the interrupt flag in ISR(), something like:

PORTA.INT0FLAGS = PIN1_bm;

(I have not looked up the exact labels.)