PSoC5LP Lab 03: UART-Based LED Control and Switch State Monitoring

Objective

  • Configure and test a UART (8‑N‑1) on PSoC 5LP at 115200 bps.
  • Map I/O pins and use digital input/output components in PSoC Creator.
  • Implement framed, case‑insensitive command parsing: #<CMD>;.
  • Debounce a pushbutton and report press/release events over UART.
  • Interoperate with a PC serial terminal to validate transmit/receive paths.

Overview

In this lab, you will explore how to use the UART interface for two-way communication between a microcontroller and a host PC. The lab is divided into two main exercises:

  • Exercise 1: You will configure the system so that the host PC can send text-based commands through the UART to control an LED (LED1). The microcontroller will process the received commands using an interrupt-driven state machine and execute the corresponding action (turning LED1 on or off).
  • Exercise 2: You will extend the functionality to allow the microcontroller to send messages back to the host PC whenever a switch (SW1) is pressed or released. This will be done using a software edge detection method, so that the system reliably detects switch state changes and reports them as "SW1 is pressed" or "SW1 is released" messages.

Through these exercises, you will gain hands-on experience in configuring digital input/output pins, implementing UART communication, handling interrupts, and designing state machines for command processing and edge detection. Together, these skills form a strong foundation for building interactive embedded systems with real-time input and output control.

.

Required Reading Materials

Required Components

picture 64x64 description × quantity
× 1
× 1

Circuit / Schematic

Procedure

Creating a New Project

  1. Launch PSoC Creator.
  2. Got to File ➤ Open Project ➤ Project/Workspace.
  3. Open the PSoC5LP workspace in the EE4450 folder.
  4. After PSoC Creator opens the workspace, right-click on Workspace 'PSoC5LP' in the Workspace Explorer and select Add ➤ New Project...
  5. Select the correct PSoC5LP device model number, use the "Empty schematic" template, and enter the project name 03_UART_GPIO.

Adding PSoC Creator Components

In this section, we will add the necessary components to the schematic (TopDesign.cysch) in PSoC Creator

  1. Add a Digital Input Pin:
    • Open the component catalog and go to the Ports and Pins category.
    • Drag and drop a Digital Input Pin onto the schematic.
  2. Add a Digital Output Pin:
    • From the same Ports and Pins category, select Digital Output Pin.
    • Drag and drop it onto the schematic.
  3. Add a UART:
    • Open the Communication category.
    • Drag and drop a UART onto the schematic.
  4. Add an Interrupt:
    • Go to the System category.
    • Drag and drop an Interrupt onto the schematic.
  5. Add a Logic '0':
    • Under the Digital category.
    • Drag and drop a Logic Low '0' onto the schematic.

After completing these steps, the schematic will include all necessary components — Digital Input Pin, Digital Output Pin, UART, Logic ‘0’, and Interrupt — ready for configuration and connection in the next stage.

Configure the Components

  1. Configure the Digital Input Pin (Pin_1):
    • In the schematic, select the Pin_1 component.
    • Rename the component to nSW1 to indicate its connections to a switch.
    • Set the Drive Mode to Resistive Pull-Up, which ensures the pin defaults to high when not pressed.
    • Uncheck the box for HW connection to disable the hardware connection, as shown in the diagram.
  2. Configure the Digital Output Pin (Pin_2):
    • Select the Pin_2 component.
    • Rename the component to LED1, showing that it drives the LED.
    • Uncheck the HW connection box so that the LED will be controlled by software.
  3. Configure the UART (UART_1):
    • Select the UART_1 component.
    • Rename the component to UART.
    • Set the following UART parameters:
      • Mode: Full UART (TX + RX)
      • Baud Rate: 115200 bps
      • Parity: None
      • Stop Bits: 1
      • Flow Control: None
  4. Configure the Interrupt (isr_1):
    • Select the isr_1 component.
    • Rename the component to ISR_UART.
    • Connect the ISR_UART to the rx_interrupt output of the UART component. This allows the interrupt service routine to be triggered whenever a character is received via UART.
  5. Configure the Digital Input Pin (Rx_1):
    • Select the Rx_1 component.
    • Rename the component to UART_Rx to indicate its role as the UART receive pin.
  6. Configure the Digital Input Pin (Tx_1):
    • Select the Tx_1 component.
    • Rename the component to UART_Tx to indicate its role as the UART transmit pin.
  7. Connect Reset Pin:
    • Connect the Logic Low '0' signal to the reset pin on the UART component.
    • This configuration disables the reset function of the UART, allowing it to remain enabled during operation.

The new TopDesign.cysch file is shown below:

The UART communication allows a host PC (using Termite or similar terminal software) to send specific commands to the microcontroller. The microcontroller will interpret these commands and toggle LED1 accordingly. The received data will be handled by an Interrupt Service Routine (ISR), while a state machine is used to process complete command strings.

Pin Assignment

DevicePort.PinDirectionDrive Mode

Template Firmware Code

Exercises

© 2025 Air Supply Information Center (Air Supply BBS)