Hi, I apologize if this has been covered, but I couldn’t find it in the documentation or on this forum. I’m trying to figure out whether calling digitalWrite() before pinMode() is or should be supported.
I have an external peripheral attached to an Electron that has weak pull-ups on some of the control lines so that they default to HIGH upon power up. After booting, I want to change the Electron pins from high impedance to HIGH outputs without glitching these control lines. I might later set them LOW, but I don’t want them to temporarily transition from HIGH->LOW->HIGH as I configure the gpio.
In a non-Arduino environment, I’d enable the peripheral clock for the pin’s port, write a ‘1’ to the pin’s data register bit, and then set the pin to an output. In Particle land, I’d expect this to translate to a call to digitalWrite(HIGH) followed by pinMode(OUTPUT). However, this didn’t work (the pins in question became LOW outputs after the pinMode() call). After inspecting the HAL code, it seems as though only a call to pinMode() will enable the port’s peripheral clock, so calling digitalWrite() before pinMode() won’t work. Thus, I don’t see a way to transition directly from a high-impedance input to a HIGH output.
Is this expected? Is there any other way to achieve what I’m trying to do with the Particle API or will I need to resort to lower-level code?