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.

  • 2
    \$\begingroup\$ The question is unclear. Which ports, on what? \$\endgroup\$ – Jeroen3 Feb 21 '18 at 10:45
  • \$\begingroup\$ Welcome to the site. Please quickly realise that this is not a free design house, homework-answering service or an on-line technical encyclopedia, copied out to you on demand. People will help you take the next step if your question shows that you've done as much as you possibly could on your own - which your post doesn't, I'm afraid. Please edit and greatly improve your question, showing your work and findings so far in considerable detail. Or delete the question if Internet searches give you your answer anyway. Again, a warm welcome to the site. \$\endgroup\$ – TonyM Feb 21 '18 at 11:56

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.

  • \$\begingroup\$ Thank you @DoxyLover. I understand. One question again. Making the pin the as output and sending 1, does it make in High -Z state, provided the device pin (outside the controller board) is configured for open drain ? \$\endgroup\$ – xyz101 Feb 21 '18 at 14:28
  • \$\begingroup\$ @xyz101 - not sure what you mean by “outside the controller board”. If your device pin is set to open-drain output and set to one, it will be high-Z. Open-drain means that there is an N FET pulling low but nothing pulling high. Setting the output to one turns off the pull-down FET so the pin floats and can be safely pulled either way externally. \$\endgroup\$ – DoxyLover Feb 21 '18 at 22:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.