Sinking and sourcing current refers to current going into and out of the MCU (respectively), right? If you configure a GPIO pin as an output, why would current ever go into the pin (since it's configured as an OUTPUT)? I suppose it depends what the output circuit looks like, if it's tied to the voltage supply rail or ground... maybe I just answered my own question...?
2 Answers
Even though it's called an output, it can sink or source current:
We are looking at the right hand pair of MOSFETs here (the left hand pair are what an input pin would look like - if the pin can perform both functions, both pairs are connected to the same pin)
When the output is high the top MOSFET is on (open/passing current) and the bottom MOSFET is off. The pin is effectively connected to the supply voltage (through the MOSFET's ON resistance)
When the output is low, the top MOSFET is off and the bottom MOSFET is on, so the pin is effectively connected to ground. So if you have a e.g. pullup resistor connected between the pin and the supply, the bottom MOSFET will sink the current and keep the voltage at the pin near 0V (assuming the resistor is not too small so the current is higher than the pin is rated for)
-
\$\begingroup\$ Exactly what I was wondering! Details of operation at the hardware level with a schematic for illustration - excellent. Thank you! \$\endgroup\$– The_DersCommented Feb 19, 2013 at 21:50
Lets say you the output pin is connected to an LED + resistor. Depending on if the LED is connected to VCC or GND (i.e. whether it is active low or active high), current will either have to flow out of (source) or into (sink) the MCU.
-
\$\begingroup\$ Great example to help illustrate the concept. Thanks! \$\endgroup\$– The_DersCommented Feb 19, 2013 at 21:51