0% found this document useful (0 votes)
92 views5 pages

UART Guide for ECE Students

The document describes examples of using a Universal Asynchronous Receiver Transmitter (UART) component in PSoC Creator to transmit and receive serial data. It discusses configuring the UART component, assigning pins, writing code to print strings and integers to a serial terminal, polling and interrupting on received data. The examples demonstrate printing a variable to a terminal, echoing received characters, and detecting a sequence of digits entered on the terminal.
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)
92 views5 pages

UART Guide for ECE Students

The document describes examples of using a Universal Asynchronous Receiver Transmitter (UART) component in PSoC Creator to transmit and receive serial data. It discusses configuring the UART component, assigning pins, writing code to print strings and integers to a serial terminal, polling and interrupting on received data. The examples demonstrate printing a variable to a terminal, echoing received characters, and detecting a sequence of digits entered on the terminal.
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

Real-time Application Exercises

Electrical and Computer Engineering

II. Universal Asynchronous Receiver Transmitter (UART)


By Prawat Nagvajara

Synopsis (Fig. 2) and the editing panel in the middle.


Application can print and receive data to and Figure 3 shows [Link].
from a serial terminal using the Universal
Asynchronous Receiver and Transmitter (UART)
component. This note introduces the UART
peripheral and goes over examples.

Introduction
Processor uses the UART peripheral for
transferring data with a serial terminal, the
RS233 serial transmission protocol. Reader can
search and learn the details of UART functions
and the protocol, for instances [1], [2]. With IDE
tools such as the PSoC Creator, an application
uses APIs to put character string to be
transmitted and to get character form the
received data buffer. This note will cover a Fig. 1 Workspace Panel
reference design on how to use the APIs to print
string and integer on the serial terminal.

Example – Printing Integer


The example shows the steps when using PSoC
Creator and PSoC 4 board, for placing and
configuring the UART component, the pin
assignment, the code and running the example
on the development kit.

Place and Configure


Open PSoC Creator IDE, and select File New
Project… In the new project window, under
Design tap select Empty Template PSoC 4
Design and for as for the project Name let’s use
“UART” and for Location reader can organize
the projects folders by browsing and creating
new folder.

The project window has 3 panels the workspace


on the left (Fig. 1), the components on the right
Fig. 2 Component Panel

1
Real-time Application Exercises

Drag and drop the UART (SBC Mode) V1.20 and


open the UART component by double clicking
on the icon (Fig. 3). In the configure SCB P4
(Switch Capacitor Block PSoC 4) configure the
basic parameters and advanced parameters and
OK (see Fig. 4 and Fig. 5).

Fig. 3 Placing UART Component


Fig. 5 UART Advanced Configuration

Reader can study through UART datasheet and


learn more about the parameters.

Build
Under the Build pulldown menu select Build
UART. The IDE build the system which includes
hardware configuration and the APIs.

Code
From the Workspace panel open main.c and
replace with the code shown in Fig. 6). Note the
APIs UART_Start, UART_UartPutString and
UART_UartPutChar. The format is that the
name of the component, “UART” and the
underscore then the generic function. For the
API descriptions see the component datasheet.
Fig. 4 UART Basic Configuration

2
Real-time Application Exercises

Configure Pins
From Workspace panel open the [Link]
to configure the UART Rx and TX ports to pins
(Fig. 7).

Fig. 7 Ports and Pins Assignment

Setup and Program Evaluation Board


On the PSoC 4 board wire P0[4] to P12[7] and
P0[5] to P12[6]. Connect PSoC 4 USB cable. The
board installs the driver and makes the
connection. Under the Debug pull menu select
Program.

Run Application
When the board is programmed the main code
starts. This code prints the variable count on
the terminal. Ascertain the COM port (serial
port) number from the Device Manager (Fig. 8).

Fig. 8 Device Manager COM Port

Results
Start a serial terminal emulator such as PuTTY
or Hyperterm and select Serial connection
parameters as shown in Fig. 9. The values of the
variable count are the output on the terminal
(Fig. 10). The new value appears at 200 ms
interval due to the delay function CyDelay(200)
which pauses the processor for 200 ms.

Fig. 6 Application Main Program

3
Real-time Application Exercises

Fig. 9 Serial Terminal Setup

Fig. 11 main() Polls Receive Buffer

Example – Interrupt When Receive Buffer Not


Empty
This example uses the UART interrupt hardware
to generate an interrupt when the receive
buffer is not empty. The design uses the
interrupt component to define the interrupt
routine.

The UART component is configured to have the


external interrupt when the receive buffer (Rx
FIFO, Receive First-in First-out) is not empty
Fig. 10 Terminal count++ Output (Fig. 12).

Example – Polling Receive Buffer


This example shows the main program code of
the previous example modification to put the
character typed back to the terminal display. In
the control loop, the for (;;) {…} loop, the code
polls whether a character receive buffer is
empty by “UartGetChar()” API if it is zero a
character has not been typed. The code for the
control loop is below (Fig. 11),

Fig. 12 UART Advanced Configuration Interrupt

4
Real-time Application Exercises

Place the interrupt component (Component


Catalog panel under System) and configure the
interrupt component: Name: Rx_ISR and the
interrupt type Derived (Fig. 13). Connect Rx_ISR
to the UART interrupt port (Fig. 14). Build the
design.

Fig. 15 Interrupt Example Code

Fig. 13 Interrupt Component Configuration

Fig. 16 Verification

Results
Fig. 14 UART with Interrupt Schematic Program the PSoC 4 board and launch PuTTY.
The program put the character typed back on
Code the terminal and when ‘X’ is typed it puts a
Open main.c and use the code below (Fig. 15). string “Got an X” (Fig. 16).

References
1. [Link]
/articles/serial_intro
2. Wikipedia
3. [Link]

Exercise
Code an application that detects the sequence
3, 7, 8, 0, 2. User enters on the terminal a
sequence of digits. A digit is an integer between
0 and 9, however, when entered from the
terminal it is an ascii (American Standard Code
for Information Interchange) character. For
instance, the character for ‘3’ is 0x33,
hexadecimal 33 an 8-bit vector “00110011”.
ASCII for ‘0’ is x30, ‘1’ is 0x31, …, ‘9’ is 0x39 [3].

You might also like