CYGNAL Integrated Products, Inc. AN015-1.0 MAR01
4301 Westbank Drive Copyright © 2001 Cygnal Integrated Products, Inc.
Suite B-100 (All rights reserved)
Austin, TX 78746
www.cygnal.com
AN015 - Software UART Examples
Relevant Devices
This application note applies to the following devices:
C8051F000, C8051F001, C8051F002, C8051F005, C8051F006, C8051F010, C8051F011, C8051F012,
C8051F012, C8051F015, C8051F016, C8051F017, C8051F220, C8051F221, C8051F226, C8051F230,
C8051F231, C8051F236.
CYGNA L Application Note
Introduction
This application note presents a discussion
about software UART implementation on
C8051Fxxx devices. Two complete examples
are given: a C program using the PCA as the
baud rate source, and an assembly program
using Timer 0 as the baud rate source.
Key Features
The two software examples were designed to
closely mimic the hardware UART while still
preserving hardware resources and CPU band-
width. The following is a list of key features
found in both examples:
• An interface similar to the hardware
UART, with user-level transmit and
receive interrupts.
• Interrupt or polled mode access support.
• Full-duplex communication up to
57.6 kbps using an 18.432 MHz clock
source.
• State-based, interrupt-driven implementa-
tion, requiring minimal CPU overhead.
• Minimal hardware usage:
- ‘C’ example uses two PCA modules.
- Assembly example uses Timer 0 in
Mode 3.
Implementation Options
The essential trade-off to consider when
implementing a software UART (SW UART)
is between hardware usage and speed/effi-
ciency. Designs that utilize more hardware are
likely to consume less CPU bandwidth and
allow higher bit rates. This trade-off is dis-
cussed below.
Baud Rate Sou rces
An interrupt must be generated for each bit
that is transferred; at a full-duplex 115.2 kbps,
that’s an interrupt every 4.3 µs. The method of
generating these interrupts (baud rate source)
determines to a large extent how much over-
head the implementation consumes. Available
options include: 8-bit timers, 16-bit timers, and
the Programmable Counter Array (PCA). Note
that for full-duplex operation, two baud rate
sources are required (one each for transmit and
receive).
The use of 8-bit timers allows one of the 16-bit
hardware timers to be used for both transmit
and receive baud rate generation. Timer 0
offers this capability in Mode 3. Note that
when Timer 0 is in this mode, Timer 1 func-
tionality is reduced; however, Timer 1 may
still provide baud rate generation for the hard-
ware UART (HW UART). Using 8-bit timers