I have one question regarding the direction of Port Pin (GPIO). Is it mandatory to change the direction of port pin to input in order to read the value from that port. Keeping the port direction as output, should we not read the value from Port? Reason because, I am trying to read the value from a different driver outside the controller board on SPI communication. In order to read the value from it, clock signals needs to be sent out.This is being done by sending 0xFFFF with direction as input and then value is read. But my problem is, in order to read the value from device, if I send 0xFFFF (to generate clock signal) with Port direction as output, I am still able to read the value from sensor. So is it real mandatory to change the port direction to input to read the value? What consequences may I face if I don't do this?
closed as unclear what you're asking by Neil_UK, RoyC, Finbarr, Voltage Spike, Sparky256 Feb 23 '18 at 3:54
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
This really depends on the specific device.
Many devices do allow you to read the state of an output pin. This is particularly useful for pins set to open-collector/drain (drive low only) as when outputting high, the hardware pin is set high-Z and an external connection is allowed to pull the pin low.
On the other hand, if the pin is set push/pull (driving both high and low), you had better not drive it externally as you can create a fight and damage one or both devices. Here, if want to read an external state, you must set the pin to input.
There are some devices that don’t have an explicit input state. Instead, you must set it to open-collector output and high output to place it in a high-Z state.
There may be some devices where when a pin is set to output, reading simply returns the set output state, regardless of the actual level of the hardware pin.
If you want a specific answer, you need to specify what device you’re asking about.