Lab 101 (AI KIT): GPIO Input and Output Control
This laboratory introduces the fundamental concepts of General Purpose Input/Output (GPIO) programming using the PSoC 6 AI Kit (CY8CKIT-062S2-AI). The experiment demonstrates how to configure GPIO pins as digital inputs and outputs, read the status of onboard push buttons, and control onboard LEDs. These techniques form the foundation of embedded system development and are essential for implementing user interfaces, sensor inputs, and device control applications.
Introduction
GPIO (General Purpose Input/Output) is one of the most frequently used peripherals in embedded systems. GPIO pins allow a microcontroller to interact with external devices by either reading digital signals from inputs or generating digital signals to outputs.
In this laboratory, the onboard LEDs and push buttons available on the PSoC 6 AI Kit are used to demonstrate basic GPIO operations. Developers will learn to configure GPIO pins in ModusToolbox, read button states in software, and control LEDs based on user input.
The knowledge gained in this laboratory serves as the foundation for future experiments involving sensors, communication protocols, and embedded control systems.
Learning Objectives
Upon completion of this laboratory, the engineer should be able to:
- Understand the purpose of GPIO peripherals.
- Configure GPIO pins as digital outputs.
- Configure GPIO pins as digital inputs.
- Read push-button states using software polling.
- Control LEDs using GPIO output signals.
- Implement simple input/output control logic.
- Develop and program a PSoC 6 application using ModusToolbox.
Required Hardware
Hardware Components
- Infineon CY8CKIT-062S2-AI Development Board
- USB Type-C Cable
- PC or Laptop
Required Software
Software Tools
- ModusToolbox IDE
- KitProg3 USB Drivers
Background
GPIO stands for General Purpose Input/Output. These programmable pins can be configured to either receive digital signals from external devices or generate digital signals to control external hardware.
Typical GPIO applications include:
- LED control
- Push-button interfaces
- Relay control
- Digital sensor interfaces
- Status indicators
For output applications, a GPIO pin drives either a logic HIGH or logic LOW voltage level. For input applications, a GPIO pin detects the voltage level present on the pin.Push buttons often require pull-up or pull-down resistors to prevent floating inputs. Floating inputs can cause unpredictable behavior due to electrical noise. Many development boards utilize active-low LEDs. In an active-low configuration:
- Logic LOW ⇒ LED ON
- Logic HIGH ⇒ LED OFF
Engineers should verify the actual LED behavior during experimentation.
Procedure
- Create a New ModusToolbox Project
- Launch ModusToolbox (Eclipse for ModusToolbox 202x).
- Select New Application from the ModusToolbox start menu.
- Under the Board Support Package (BSP) selection window, choose:
PSoC™ 6 BSP → CY8CKIT-062S2-AI - Select the application template:
Getting Started → Dual-CPU Empty PSoC™ 6 App - Enter the project name:
Lab101_1_GPIO_LED - Click Create to generate the project.
- Open the Project
After the project has been created, ModusToolbox™ may automatically download and install any required BSP packages, middleware libraries, and software dependencies from the Internet. This process may take several minutes, depending on the network connection and the installed software components.
Once the installation is complete:- Locate the Project Explorer window.
- Expand the project: Lab101_1_GPIO_LED.proj_cm4
- Open the source file: main.c
- Review the project structure and become familiar with the generated application framework before proceeding.
- Configure GPIO Resources
Following the requirements of each experiment:- Add the necessary GPIO initialization and configuration statements in the program's initialization section.
- Place the GPIO configuration code before the main execution loop:
for (;;) { } - Configure the required GPIO pins as either:
- Digital Outputs (LEDs)
- Digital Inputs (Push Buttons)
- Verify that the selected GPIO pins correspond to the appropriate onboard hardware resources.
- Implement the Control Logic
Inside the main execution loop:
perform the following tasks:for (;;) { }- Read the state of the input GPIO pins.
- Process the input conditions according to the experiment requirements.
- Update the output GPIO pins accordingly.
- Add an appropriate software delay if required to:
- Generate blinking patterns
- Reduce processor utilization
- Implement simple switch debouncing
- Build and Program the Application
Build the Project- Save all modified source files.
- Select: Build Project
- Verify that the project compiles successfully without errors or warnings.
- After ModusToolbox has installed all necessary components from the internet, your project is ready to use. In the Project Explorer window, open > Lab101_1_GPIO_LED.proj_cm4, double click on "main.c" to open the main.c in the editor.
- Following the lab experiment instructions, add GPIO configuration statements before the "for (;;)" loop.
- In the "for (;;)" loop, add the control code to read the input pin's state, then control the output pins. You may need to add a delay function at the end of the for-loop.
- Build and Program:
- Build Project
- Program the board: If there are no errors, click "Lab101_1_GPIO_LED.proj_cm4 Program" to download the binary code into the PSoC 6 MCU.
- Verify successful programming. You should get the expected results in each lab experiment.
- Execute Experiments.
Complete all experiments described in the next section.
Set output pin using GPIOA->DATA |= _PIN1.