Interrupts on Arduino DUE

Hello I need some help. I Use the Arduino Due with the Arduino-IDE. I want to generate Interrrupts on the PIO. The Interrupt should generate at a Pin Change and I dont't want to use the attachInterrupt() function. In the following I show the Code from Arduino-IDE. It's just to check if an interrupt occur.

volatile boolean a = 0;

void PIOD_handler()
{
  a=!a;
}

void setup() 
{
 Serial.begin(115200);

/*Enables the PIO to control the corresponding pin*/
REG_PIOD_PER = REG_PIOD_PER | 0x0000000F;

/*Enables the Input Change Interrupt on the I/O line*/
REG_PIOD_IER = REG_PIOD_IER | 0x0000000F;

/*Enables Interrupts on PIOD*/
NVIC_EnableIRQ(PIOD_IRQn);
}


void loop() 
{
Serial.println(a);
}

Can anybody help me? I can't find the mistake

this seems too simplistic to me. you need to be sure that the right device (PIOD) is multiplexed to the SAM's pins. the easiest way to do this is to do pinMode() calls at the beginning.. but it's also possible to use Atmel's PIO_Configure() calls for this. Also a very common thing to look out for is that in many interrupt handlers you will need to readout the interrupt status from some hardware register, otherwise it won't retrigger..

what i would do is check out the attachInterrupt() and pinMode() source code.. as a place to start.

in any case you will need to configure if you want triggering on rising/falling edges or both.

http://www.atmel.com/Images/Atmel-11057-32-bit-Cortex-M3-Microcontroller-SAM3X-SAM3A_Datasheet.pdf see figure 31-7 ..

and indeed in the handler you will have to read out PIO_ISR to clear the interrupt's pending state.