M4 Interrupt problem / interference pin19

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
david84
 
Posts: 9
Joined: Mon Jan 13, 2014 3:06 pm

M4 Interrupt problem / interference pin19

Post by david84 »

On a ItsyBitsy M4 Express, pins 2 and pins 3 work well with attachInterrupt(). But if I try to intercept interrupt on pin 19 (or A5), pin 2 still trigger interrupt, but pin 3 does not anymore trigger anything and pin 19 does only 1% of time...
If I read the values with digitalRead() inside the loop, I can verify that the values change correctly, but no interrupt are triggered on pin 3 and only sometime on pin 19...
I did not try some other combination of pins, and did not try also another board...
May I did something wrong? Any Idea?
Thanks !

Code: Select all

void setup() {
  Serial.begin(9600);
  delay(1000);
  pinMode(2, INPUT); attachInterrupt(2, onPin2, CHANGE);
  pinMode(3, INPUT); attachInterrupt(3, onPin3, CHANGE);
  pinMode(19, INPUT); attachInterrupt(19, onPin19, CHANGE);
} // end setup

void loop() {
  delay(500);
  Serial.println( (digitalRead(2)<<2) + (digitalRead(3)<<1) + digitalRead(19), BIN);
} // end loop

void onPin2() {Serial.println("2");}
void onPin3() {Serial.println("3");}
void onPin19() {Serial.println("19");}

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: M4 Interrupt problem / interference pin19

Post by westfw »

Unfortunately, pin 3 and pin 19 have the same "hardware interrupt" vector, which means that only one of them can actively generate interrupts - this is a limitation of the way Atmel implemented pin interrupts in the whole SAMD series :-(

See https://docs.google.com/spreadsheets/d/ ... sp=sharing

(This is somewhat buried in the datasheet. See the footnotes in section 23.6.6:
If an external interrupts (EXTINT) is common on two or more I/O pins, only one will be active (the first one
programmed).
Grr.)

User avatar
david84
 
Posts: 9
Joined: Mon Jan 13, 2014 3:06 pm

Re: M4 Interrupt problem / interference pin19

Post by david84 »

Thanks for explanation, I understand, and will be careful on this point.

I like to understand correctly when I encounter a problem, to prevent futur disappointment... but the MCU documentation is very difficult to understand about "vector interrupt".
→ How did you build the table you linked above?...

Another point is that I suggest that you add some information about this on your "learn" page:
https://learn.adafruit.com/introducing- ... m4/pinouts
Chapter "Logic pins" writes "All pins can be interrupt inputs" and it's the reason why I bought a ItsyBitsy M4... perhaps may you add something like "... but not all at the same time" or something like that...

By the way, thanks for your products and your excellent and very useful documentation and opensource libraries that I use all the time since years ! :o)

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: M4 Interrupt problem / interference pin19

Post by westfw »

How did you build the table you linked above?...
My Google Spreadsheet? It's mostly a manual copy of table 6-1 (I/O Multiplexing and Considerations) from the datasheet, with the board pin numbers derived from the various variant.cpp files in the samd Core source code. I find it very ... educational ... to put together such spreadsheets for any chip I'm interested in.

The "not at the same time" is pretty buried in the datasheet; you need to look at the "16 external interrupts" claim, and the multiplexing table that lists the same interrupt for multiple pins, and then find out what happens if you want multiple pins to cause the same interrupt. Which is that ONE footnote - it took me a while to find that in the datasheet even though I knew it was there...

IMO, this was bad chip design. They (Atmel) should have let ANY pin with the same interrupt cause the interrupt, and allowed software to figure our which one it was (similar to the way pin-change interrupts work on AVR.) Sigh.

User avatar
david84
 
Posts: 9
Joined: Mon Jan 13, 2014 3:06 pm

Re: M4 Interrupt problem / interference pin19

Post by david84 »

Thanks a lot westfw for your support 👍

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”