-
-
Notifications
You must be signed in to change notification settings - Fork 7k
pinMode OUTPUT sets HIGH after digitalWrite set LOW on Arduino Due #3310
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
Comments
Setting the pin to low by default (as pull request #3317 does) might be safer than setting it high, but it still doesn't make the behavior of the Arduino Due compatible with other Arduino boards so it's not that great. On the Arduino Uno and Leonardo, if you want to set an output to be high without having it temporarily drive low (which could break things), then you have to do it with this sequence of commands:
And if you want to drive it low without temporarily driving it high, you have to use this sequence:
Currently, the first sequence would work on the Arduino Due and the second sequence would not work. Pull request #3317 simply changes it so that the first sequence doesn't work and the second sequence does work. (At least that is my current understanding; sorry if I missed something.) In my opinion, for any board to be called "Arduino compatible" both of those sequences should work. If one of them doesn't work, then you will have trouble running code and libraries that depend on the traditional behavior. There is at least one library where the code had to be changed to work around this non-standard behavior of the Arduino Due: https://github.com/pololu/a4990-motor-shield/blob/0f5279c2bbfab8fabb29392ce6a0a59e20951e2d/A4990MotorShield/A4990MotorShield.cpp#L12-24 I haven't looked into the details, but it might be that for the Arduino Due, the Arduino core code actually needs to emulate the PORTx and DDRx bits of the AVR, and treat Even if you don't care about compatibility with existing Arduino code and other Arduino boards, it seems like it is an important feature to be able to set an I/O pin to be low without having it temporarily drive high, and vice versa. Right now it looks like the Due just doesn't support that, at least when you are using |
I see that my issue is wrongly described, sorry about that. If I do not call digitalWrite before pinMode, the default Arduino output would be HIGH? The workaround in A4990MotorShiled works great? I mean, it never gets high, not even by a millisecond? The issue in Due will ever be fixed? |
The workaround in the A4990 library is not perfect, no. The line will be high for a short time after we call pinMode on it. |
@DavidEGrayson Can you set the labels? If there is another open issue, please mark this as duplicate and close it. Thank you. |
Sorry, I'm not an Arduino developer, just someone commenting on this issue. |
Would you like to try the solution on #3524 and give feedback there? |
Solved by #3524 |
Architecture: SAM
Board: Arduino Due
When the pin is defined as OUTPUT it automatically sets HIGH in that pin, even when digitalWrite previously set it LOW. This is different behavior from AVR.
I need all DO set low at startup, so in Arduino/hardware/arduino/sam/cores/arduino/wiring_digital.c. To make pinMode output LOW by default, change PIO_OUTPUT_1 to PIO_OUTPUT_0.
See http://forum.arduino.cc/index.php?topic=185230.0 and http://forum.arduino.cc/index.php?topic=154869.0
The text was updated successfully, but these errors were encountered: