1
\$\begingroup\$

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?

\$\endgroup\$
4
  • \$\begingroup\$ It might be provided through a whole bunch of different components. Or not provided at all if it is an open-drain output. Microcontrollers are complex beasts. \$\endgroup\$ – Eugene Sh. Apr 15 at 14:39
  • 1
    \$\begingroup\$ The data bus sets the value of the register, but then the register remembers what value it was set to. So, once the register has a value set, the data bus is no longer important (until the processor sets another value, or reads the value). The register may (or possibly not) have buffer circuitry which allows the io pin to handle higher voltage or current than the register (which in that case only stores the value, but does not drive the io pin.) \$\endgroup\$ – Math Keeps Me Busy Apr 15 at 14:51
  • \$\begingroup\$ @MathKeepsMeBusy, for clarity, avoid the word 'set' for 'writes to'/'puts to' etc. Set and reset already mean 'store 1' and 'store 0' in piles of digital logic datasheets and documentation on flip-flops and latches. Thanks. \$\endgroup\$ – TonyM Apr 15 at 15:05
  • 1
    \$\begingroup\$ Does this answer your question? What actually happens when we set direction on GPIOs in controllers ? It explains both directions. \$\endgroup\$ – Passerby Apr 15 at 15:20
3
\$\begingroup\$

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...

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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