[FIXED][Interrupts] Is this a bug? (patch available)

Hi! :slight_smile:
I spent a couple of hours trying to make a sketch work with my new Arduino Due, then I discovered a strange thing: some interrupts are never triggered...

It's clearly stated that the Arduino Due is able to attach an interrupt on any available pin (source: http://arduino.cc/en/Reference/AttachInterrupt) but it seems that interrupts on the following pins are not working: 11, 12, 14, 15, 20, 21, 25, 26, 27, 28, 29, 30, 32, A7. (I can read values correctly from each of them, but no interrupt callback is ever called)

Can anyone confirm this?

I wrote a simple sketch that attaches an interrupt to any pin from 2 to 53 and from A0 to A11:

void setup() {
	Serial.begin(9600);
	while (!Serial) {
		;
	}
	
	uint8_t pins[64] = {
	//	TX0 and RX0 can't be checked this way...
	//	0,
	//	1,
		2,
		3,
		4,
		5,
		6,
		7,
		8,
		9,
		10,
		11,
		12,
		13,
		14,
		15,
		16,
		17,
		18,
		19,
		20,
		21,
		22,
		23,
		24,
		25,
		26,
		27,
		28,
		29,
		30,
		31,
		32,
		33,
		34,
		35,
		36,
		37,
		38,
		39,
		40,
		41,
		42,
		43,
		44,
		45,
		46,
		47,
		48,
		49,
		50,
		51,
		52,
		53,
		A0,
		A1,
		A2,
		A3,
		A4,
		A5,
		A6,
		A7,
		A8,
		A9,
		A10,
		A11
	};
	
	for (uint8_t i = 0; i < 64; i++) {
		pinMode(pins[i], INPUT);
		attachInterrupt(pins[i], callback, CHANGE);
	}
	
	Serial.println("READY!");
}

void loop() {
	// Nothing...
}

void callback() {
	Serial.println("IT WORKS!");
}

Trigger the interrupts manually and see what happens...

Note: I know that using complex callbacks is a bad idea, but I had the same result with lighter callbacks...
Note2: If you are wondering... no, it does not work even if you attach one single interrupt to any of the pins listed above... and the affected pins are always the same. (at least till now)

Hi Liarco.
Which Arduino IDE version you are running?

Thank you for your reply! ^^

Arduino IDE: 1.5.1
OS: Mac OSX 10.7.5

I also noticed that my "L" led (pin 13) is always ON (even if I load an empty sketch)... I hope I haven't ruined my board! :frowning:

Liarco,

thank you very much for the detailed and precise bug report.

the pins you're listing here seem to have in common one thing: they all belongs to PORTD (well, except 2).
Looking back at the interrupt implementation aehm portd is not considered at all... :blush:

Adding support for missing pins should be simple, I'll try to do it now.

Ok done, I did quick test and the interrupt seems to work now.

the patch is here:

If you want to check it out, grab the file WInterrupts.c from here:

and replace the one in hardware/arduino/sam/cores/arduino/WInterrupts.c.

Also the pins 20, 21 and A7 that doesn't belong to PORTD are working for me.

I'm going to try this patch as soon as I can, thank you very much for your quick support! :slight_smile:

It works like a charm! :smiley:

Thank you very much.

Main post title updated.