0% found this document useful (0 votes)
2 views11 pages

GPIO - Peripheral Lecture 3 - 240927 - 145239

The document outlines a session on microcontrollers and applications focusing on the STM32 General Purpose Input Output (GPIO) peripheral. It details the configuration, operating modes, and functionalities of GPIO pins, including how to read, write, and toggle pin states. Additionally, it includes a practical task for trainees to implement LED blinking and control using GPIO functionalities.

Uploaded by

2400801250
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)
2 views11 pages

GPIO - Peripheral Lecture 3 - 240927 - 145239

The document outlines a session on microcontrollers and applications focusing on the STM32 General Purpose Input Output (GPIO) peripheral. It details the configuration, operating modes, and functionalities of GPIO pins, including how to read, write, and toggle pin states. Additionally, it includes a practical task for trainees to implement LED blinking and control using GPIO functionalities.

Uploaded by

2400801250
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/ 11

Tet la’ngech

Embedded Systems Technology


Third session – 03/09/2024
TETE 3102 MICROCONTROLLERS AND APPLICATIONS
Lecturer: Dickson Mugerwa (Ph.D.)
Prac session: Mr. Matovu Paul
Department of Electrical and Electronics
Engineering

Embedded Systems
STM32 General Purpose Input
Output (GPIO) Peripheral

“Innovating for progress with embedded systems”

1
GPIO: GPIO Basics
❑ GPIO pins serve as the interface between the microcontroller and the
external world. They can be configured as either input or output.

Key attributes of GPIO:


❑ Direction – Input (reading signal) or Output (driving external device)
❑ Mode – Input/Output, Analog or Alternate function
❑ Speed – How fast the voltage changes
❑ Pull-up/pull-down – Optional resistors that affect the default state of the
pin
GPIO: GPIO Registers
STM32 MCUs provide several registers to configure and control GPIO pins

❑ GPIOx_MODER: Sets the pin mode (input, output, alternate function, or


analog).
❑ GPIOx_OTYPER: Configures the output type (push-pull or open-drain).
❑ GPIOx_OSPEEDR: Sets the output speed.
❑ GPIOx_PUPDR: Configures pull-up and pull-down resistors.
❑ GPIOx_IDR: Reads the input data register (for reading input pins).
❑ GPIOx_ODR: Writes to the output data register (for setting output pins).
❑ GPIOx_BSRR: Sets or clears individual bits in the output data register.
❑ GPIOx_AFRL and GPIOx_AFRH: Configure alternate function mappings.
GPIO: Operating modes
❑ Each port bit of the general-purpose I/O (GPIO) ports can be individually
configured by software in several modes:

Output mode: push-pull


Input mode: floating,
or open drain + pull-
pull-up/down, analog
up/down

General
Purpose
Alternate functions: Input
❑ USART/UART Output
❑ SPI
❑ I2C
❑ TIMERS/PWM Analog (ADC)
❑ External Interrupts
GPIO: Pin Configuration

❑ Configure the Pin Mode:


input/output
❑ Set Output Type and Speed (if
output).
❑ Configure Pull-up/Pull-down (if
needed).
❑ Set the pull-up/pull-down resistors
❑ Read/Write/Toggle.
GPIO: Basic Functionalities
❑ Write – Set the status of a GPIO pin
HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
HAL_GPIO_WritePin(Port Number, Pin Number, Pin State)
❑ GPIO – General Purpose Input Output
❑ GPIO_TypeDef*, uint16_t & GPIO_PinState are data types
❑ GPIOx – Port Number
❑ GPIO_Pin – Pin Number
❑ PinState – State of GPIO pin
❑ PinState; GPIO_PIN_RESET (0), GPIO_PIN_SET (1)
❑ Sample application: Turn LED on or off
7
GPIO: Basic Functionalities
❑ Toggle (Blink) – Change the status of a GPIO pin
HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
HAL_GPIO_TogglePin(Port Number, Pin Number)
❑ Sample application: Blink LED (Turn LED on & off)

8
Task: Trainees
❑ Blink the BLUE_LED for five times every
second and then turn on the RED_LED for
five seconds.

9
GPIO: Basic Functionalities
❑Read – Get the status of a GPIO pin
HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
HAL_GPIO_ReadPin(Port Number, Pin Number)
❑ Sample application: Read input from Tactile switch on Sipi education kit

10
GPIO: Basic Functionalities
External Interrupt – Rising, Falling, Rising or Falling
❑ Rising – Rise in Voltage
❑ Falling – Fall in Voltage
❑ Rising or Falling – Rise or Fall in Voltage
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
void HAL_GPIO_EXTI_Callback(Pin Number)
Sample application:
❑ Programming almost all sensors,
❑ Using sipi tactile switches to perform a certain task e.g. blink
11
an BLUE_LED
Contact Us

Get In Touch With Us


Contact Us
For more information and inquiries

Plot 1828 Block 210


Kyebando Central, Kampala-Uganda

[email protected]

www.tetlangech.com

@tetlangech

You might also like