1

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?

winny
  • 13,064
  • 6
  • 46
  • 63
  • 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. – Eugene Sh. Apr 15 '21 at 14:39
  • 1
    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.) – Math Keeps Me Busy Apr 15 '21 at 14:51
  • @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. – TonyM Apr 15 '21 at 15:05
  • 1
    Does this answer your question? [What actually happens when we set direction on GPIOs in controllers ?](https://electronics.stackexchange.com/questions/222943/what-actually-happens-when-we-set-direction-on-gpios-in-controllers) It explains both directions. – Passerby Apr 15 '21 at 15:20

1 Answers1

3

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

Marcus Müller
  • 88,280
  • 5
  • 131
  • 237