0% found this document useful (0 votes)
24 views6 pages

GPIO Quick Reference Guide

The document provides a comprehensive guide on General-Purpose Input Output (GPIO) for microcontrollers, emphasizing its importance in embedded systems, IoT, and robotics. It details the functionality of GPIO registers, including pin configuration and current flow, while cautioning about maximum current limits and internal resistance. Additionally, it highlights practical applications and scenarios for mastering GPIO skills.

Uploaded by

Teju Dave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

GPIO Quick Reference Guide

The document provides a comprehensive guide on General-Purpose Input Output (GPIO) for microcontrollers, emphasizing its importance in embedded systems, IoT, and robotics. It details the functionality of GPIO registers, including pin configuration and current flow, while cautioning about maximum current limits and internal resistance. Additionally, it highlights practical applications and scenarios for mastering GPIO skills.

Uploaded by

Teju Dave
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Mastering Microcontrollers

GPIO​
Quick Reference Guide
___

By EWskills

Why Understanding GPIO Matters:

●​ Basic Building Block: GPIO is the first hardware skill most beginners learn in embedded
systems.
●​ Control Projects: It lets you interact with devices—turn things on/off, read inputs, and
automate tasks.
●​ Learn Digital Logic: Helps you understand how timing and signals work in electronics.
●​ Essential for IoT & Robotics: Most smart devices and robots use GPIO to talk to sensors
and control parts.
●​ Connects Code to the Real World: GPIO lets your software physically sense or control
things around it.
2

🚀 Practice real-world tasks & problems for GPIO to build pro-level skills — Click here
GPIO
●​ General-Purpose Input Output (GPIO) used for INPUT and OUTPUT.
○​ GPIO INPUT → switch, buttons, keypad.
○​ GPIO OUTPUT → LED, Relay, 7-segment display

GPIO Registers
Generally, in controllers (AVR, PIC), the following types of GPIO registers are present.​
Considering the AVR controller

Register Purpose

DDRx Configures pin direction (1 = output, 0 = input)

PORTx Sets pin output level OR enables internal pull-up

PINx Reads the voltage level on input pins (5V = logic 1, 0V = logic 0)
where x = port number (eg, B, C, D)

NOTE: ARM and RISC-based 32-bit controllers have more add-on registers (e.g.,
PIN-function-selection register, pullup-configuration register, etc).

DDRx PORTx STATE

0 0 INPUT HIGH-IMPEDANCE (floating)

0 1 INPUT PULLUP

1 0 OUTPUT LOW (0V)

1 1 OUTPUT HIGH (5V)


3

INPUT HIGH IMPEDANCE (Hi-Z)


It's like an open circuit — the pin 'floats' and its voltage can randomly vary due to electrical noise,
making it unreliable unless we connect external voltage to it.

Connecting switch
Without internal PULLUP & PULLDOWN

With internal PULLUP & PULLDOWN


4

Source & Sink current


●​ Source: The current flows from the GPIO pin to the load. (e.g. GPIO HIGH powering an
LED).
●​ Sink: The current flows from the load into the GPIO pin (which acts like ground). (e.g.
LED cathode (- ve) connected to GPIO).​

Max Limits: ​
Each microcontroller has max source/sink current capacity per pin. Exceeding it can damage
the pin or controller.

E.g. – ATmega328 has a max GPIO source / sink current limit of 40 mA. Although it is
recommended to keep it minimum (< 20 mA).

GPIO Port’s current limit:​


Controller’s PORT also has its own limits for source/sink current.

E.g., AVR ATmega328 PORTC has a max sink current limit of 100 mA. As it has only 3 PORTs, the
max source/sink current it can handle is up to 300 mA.​
5

GPIO Internal Resistance


Controller's GPIO has some internal resistance e.g., ~25Ω for AVR ATmega328.​
So when OUTPUT is HIGH and current flows, it drops the GPIO voltage.

GPIO current Internal voltage drop (approx) GPIO voltage (approx)

0 mA 0 mV 5V

10 mA 250 mV 4.750 V

20 mA 500 mV 4.5 V

40 mA 1V 4V

GPIO cautions ​
GPIO Short Circuit Scenarios:

GPIO Source Sink cautions (AVR ATmega328p)​


6

How a Controller Decides HIGH or LOW on GPIO Input

Most of the controllers have a similar range as above.

🚀 Practice real-world tasks & problems for GPIO to build pro-level skills — Click here

You might also like