Electronic – Voltage to GPIO pins

busgpiomicrocontroller

Interested in Embedded Systems, I'm coming from Computer Science background.
There is a thing that I can't get my head around for awhile about pins of GPIO.

Let's say that we have a port which is associated with two register (direction register and data register) and that we set a certain digital pin as output. When we set the bit to 1 in the data register, corresponding to that output pin, does it mean that the microcontroller starts providing constant voltage to that pin? If so, is the voltage provided through the data bus to the data register (which I don't think it to be the case) or is there a wire from the pin to power source to get the voltage?

Best Answer

When we set the bit to 1 in the data register, corresponding to that output pin, does it mean that the microcontroller starts providing constant voltage to that pin

Yes.¹

Actually, the start the device doing that is when you write the direction register – at that moment, what's currently in the data register becomes applied to the pin.

If so, is the voltage provided through the data bus to the data register (which I don't think it to be the case) or is there a wire from the pin to power source to get the voltage?

ENODEF; that's not defined, it depends on how your microcontroller is built.

In most modern microcontrollers, there's specific power rails that supply mainly the IO pins' out- and input circuitry, and the digital logic controls that circuitry. But, especially in older processors, these pins often weren't strongly driven (able to supply a few microampere only) and that might have happened from some internal logic.


¹ "Constant voltage" is a bit of a simplification: obviously, microcontroller pins can't source or sink infinite current, so, there's no "perfect" constant voltage there; also, there's different kinds of IO types in microcontrollers: BJT or CMOS push/pull outputs, open drain, open collector, differential outputs, specific signalling levels, there's often things like optional slew rate limiters...