From d80877d5704ba0b4871651f144c50402aa3c5d62 Mon Sep 17 00:00:00 2001 From: Bob-the-Kuhn Date: Mon, 7 Aug 2017 21:19:15 -0500 Subject: [PATCH] Set pinMode with every digitalWrite (legacy compatibility) --- Marlin/src/HAL/HAL_LPC1768/arduino.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Marlin/src/HAL/HAL_LPC1768/arduino.cpp b/Marlin/src/HAL/HAL_LPC1768/arduino.cpp index 3f2e101a5c..d24482b751 100644 --- a/Marlin/src/HAL/HAL_LPC1768/arduino.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/arduino.cpp @@ -121,6 +121,16 @@ void digitalWrite(int pin, int pin_status) { LPC_GPIO(pin_map[pin].port)->FIOSET = LPC_PIN(pin_map[pin].pin); else LPC_GPIO(pin_map[pin].port)->FIOCLR = LPC_PIN(pin_map[pin].pin); + + pinMode(pin, OUTPUT); // Set pin mode on every write (Arduino version does this) + + /** + * Must be done AFTER the output state is set. Doing this before will cause a + * 2uS glitch if writing a "1". + * + * When the Port Direction bit is written to a "1" the output is immediately set + * to the value of the FIOPIN bit which is "0" because of power up defaults. + */ } bool digitalRead(int pin) {