INF2004 WK2PREP GPIO Principles
INF2004 WK2PREP GPIO Principles
General principles
of GPIO
Contents
Device 1
Microcontrollers and system-on-chip CPUs
GPIO
typically contain built-in I/O hardware. So do many
'smart' peripherals. GPIO
Microcontroller
Device 2
EIA232
When you connect them, try to use built-in I/O SPI
SPI
hardware to 'talk' to it, if possible. But if your I2C
peripheral uses a different protocol, connect it to USART
Device 3
GPIO pins, and write a program to control them. USB I2C
Memory
SINGAPORE
INSTITUTE OF
TECHNOLOGY
● Most microcontrollers have multiplexed pins. Each pin can be set to have
several functions. To use a pin for GPIO, first set its mode.
● Input pins can be configured with an internal resistor (or use an external one).
● Output pins can often be configured to have high/low drive strength.
● Finally, a single port can have input and output pins (along with pins that are
disabled or used for their alternative function). For example:
Bit 0 = input
Bit 1 = input
Bit 2 = output
I/O alt. Bit 3 = used for alternative function
Port A X Bit 4 = disabled
Bit 5 = output
Bit 6 = output
Bit 7 = input
SINGAPORE
INSTITUTE OF
TECHNOLOGY
So that's covered the general principles of GPIO – true for most types of
microcontroller. What we haven't looked at so far is;
1. How to use GPIO in a high level language like 'C'.
We use GPIO most commonly for driving LEDs as indicator lights (outputs),
and for connecting switches (inputs). On the switches there are a couple of
things we will note later;
1. How to debounce inputs.
2. How to scan a matrix of switches/buttons.
SINGAPORE
INSTITUTE OF
TECHNOLOGY