9 years, 1 month ago.

DigitalInOut bug?

I am using the DigitalInOut to switch between output and Hi-Z. When I go back and forth between input and output mode the state in output mode switches to randomly beeing high or low. I can fix this by setting the correct state after I have configured it as an output. But that is not very good. I like to set logic level before I switch to output to make sure it does not enter a unwanted level for a short while.

It seems it has to be in output mode for write logic level to work. It also seems the it remembers what logic level it was exposed to when in input mode when you make switch to output mode. Can it be so that pin input state and pin output state shares the same register and that is causing my problem.

It would be fantastic if initial logic state could be set every time you set it as an output.

I know you can set initial logic level when you declear the digitalInOut pin first time, but this does not help me.....

1 Answer

9 years, 1 month ago.

If will be dependent on the way the manufacturer has created a part but for the LPC1768 and I suspect just about all of the parts there is a single GPIO pin value register rather than independent input and output value registers. This means that when a pin is in input mode the value in this register reflects the current input signal, when you switch the pin mode to output it will initially drive the pin to whatever the input state was.

You could avoid any overhead in the libraries by using direct register accesses and so minimize the time between switching modes and driving the output state to the value you want but there is no possible way to completely eliminate this delay.

That said since it's driving the output to the same state as it is currently in I'm not entirely sure why this short delay is an issue to start with.

Accepted Answer

I am actually not sure if the LPC1768 and most others do this. The read/write register has the same address, but I don't know if it copies the current state when switching from input to output, since I think they are different physical registers.

I do know the LPC1114 this is specifically mentioned as a feature. I also agree with your last part: While it might add a short delay that is the only downside.

posted by Erik - 05 Mar 2015

Thank you very much! I will find a workaround. I am using LPC1114...

posted by Johan Stenberg 06 Mar 2015