If we think about what we normally do with the pins we should be about to work out what will or wont work.
Lets start with the “pin as input”. With this it should end up in high impedance thus allow very little current to flow. You then have 4 Main choices.
- External Pull up
- External Pull Down
- Internal Pull Up
- Internal Pull Down.
The use of external pull up/down give you more control over the strength as you can set the value of the resistor, when using internal it will be what ever is inside the controller.
So if we stick with internal pull up/down, we now need to work out which one.
If you use a pull down, then the default state will be “low” and with a “pull up” the default state will be “high”. defaults states can be good as floating will lead to an unknown state.
So now if we look at the “Set/Output” Pin. as an output it will either be high Vcc or low Gnd.
So if we use the internal pull up - what does this look like
When the output pin is High
Vcc → Internal Resistor → GPIOx (As input) → GPIOy (As output) → Vcc (So no current flow and Input will see “high”
When the output pin is low
Vcc → Internal Resistor → GPIOx (As input) → GPIOy (As output) → ground (So current flow as the “output” GPIO will pull down the voltage and drain to ground via the pull up resister. The Input pin will now see a low
So if we use the internal pull down - what does this look like
When the output pin is High
Gnd → Internal Resistor → GPIOx (As input) → GPIOy (As output) → Vcc (So current will flow from the output pin to ground via the pull down resistor. this will let the input pin see a high level.
When the output pin is low
Gnd → Internal Resistor → GPIOx (As input) → GPIOy (As output) → ground (So no current flow. The Input pin will now see a low level
So that seems OK, BUT we need to keep in mind what could happen.
Let say at boot or a coding error.
If Both are output, then nothing should sink any power.
If Both are input, no pull up/down then to power to flow anywhere.
If Both are output, with a pull up/down then that’s via the internal resistor.
Edit:
The main thing I can see as not a good idea would be connecting two output GPIO together. If one was High and the other low, that would be a short to ground. This is where an inline resister would provide some protection to some bad code..
Just need to consider the values to ensure safe currents and the voltage divider you would create is ok so the input pin will still see a “high” voltage.
Note: any current draw / sink must be writhing the safe range for the controller you are using; so always check the datasheet.