New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interrupts on Due with pinMode OUTPUT, and switching pinMode #1693
Comments
I've found out that executing pinMode is unattaching interrupts on DUE, maybe digitalWrite does that too. |
I used the following code to test it: void setup()
{
Serial.begin(9600);
}
void myFunc() {
Serial.println(3);
}
void loop() {
byte command;
if (Serial.available()) {
command = Serial.read();
switch(command) {
case '1':
attachInterrupt(18, myFunc, CHANGE);
Serial.println(1);
break;
case '2':
pinMode(18, INPUT_PULLUP);
Serial.println(2);
break;
}
}
} |
Came across this issue on my PS2 keyboard libraries using V1.6.7 and Due board manager 1.6.6. My workaround for the library was put an architecture dependent detach and attach interrupt around the direction change for sending to the keyboard see PS2KeyAdvanced, this is then handled correctly and works seamlessly for me. Tested same library now on Uno/Mega/Due recently. I expect some differences there are others as in AVR char is signed, SAM (Due) it is UNsigned so beware. |
Hello |
This issue was moved to arduino/ArduinoCore-sam#26 |
There are two differences in the behaviour of interrupts on a Due, after comparison to an Uno (well actually a Duemilanove).
First - When I attachInterrupt() to FALLING on a digital pin, and drive the pin as an OUTPUT between HIGH and LOW, I would expect the interrupt to trigger each time the output pin is set low. This happens on the Uno, but NOT on the Due, where the interrupt only seems to fire once.
Test case:
The expected behaviour can be obtained on the Due by replacing the digitalWrite() with digitalWriteDirect():
Now both Uno and Due count up as expected.
Second - Switching the pinMode() on a Due seems to detach the interrupts set up on the pin. You need to call attachInterrupt() again after changing e.g. from input to output mode. Again this is different behaviour from the Uno, where there is no need to do this.
Test case (replaces loop in first test case):
More details on the forum:
http://forum.arduino.cc/index.php?topic=199320.0
Note that this difference in behaviour causes e.g. the PS2KeyboardExt2 library not to work on a Due, since the library relies on either the host or the keyboard being able to send data on the CLOCK & DATA lines. The call to pinMode() causes the interrupt on the CLOCK line to stop triggering.
The text was updated successfully, but these errors were encountered: