(MCUs) can be
classified in many ways
by different criteria.
But, for this article, we
will divide them into
only two categories:
the ones that
already have a
built-in serial port
and the ones that
We all know the
importance of serial
to our daily life and
the convenience of
in achieving this goal.
So, what do you do
if you have a
does not have a
built-in serial port?
■ FIGURE 1. Transmit “X.”
Using Bit-Banging Techniques
The answer is not to abandon it,
nor avoid using it. But rather, to
create a software serial port for it. This
is not as daunting a task as you might
think. It only takes some time to learn
and try. You will find the results are
very interesting and rewarding.
I will present two practical examples to show — from simple to complex
— how easy (or how difficult) it is to do
so. First, let’s review the serial port.
Serial Port Basics:
9600 bps, 8N1
We’re all familiar with a PC serial port. Compared to a parallel port,
the main difference is it transmits
data one bit at a time. (That can save
a bunch of wires!) So, there are only
two wires needed: TX (transmit) and
RX (receive) for data transmission.
Actually, a common ground (GND)
wire is needed, as well.
The CPU of a microprocessor
does not handle data one bit at a
time (it’s too inefficient!), so the task
of serial data transmission is relegated to a special hardware part called
a UART (Universal Asynchronous
The UART is the heart of a serial
port, where a mechanism is provided
to convert a byte into a series of bits
for transmission, and vice versa for
reception. To make this happen, first
and foremost, the UART must have an
accurate bit rate (baud rate) generator. The serial port speed is defined in
bits per second (bps) and is governed
by the baud rate generator.
Of course, the UART also
has other hardware to check for
transmission status and errors, flow
control, etc. But the essential parts
are the above-mentioned three in
order to get it up and running.
Each byte of data is transmitted in
this sequence: Bit 0 or the least significant bit (LSB) first, then bit 1 through
bit 6, then finally bit 7 or the most
significant bit (MSB) last. In order to
signify the beginning and end of each
byte transmission, the RS-232 protocol adds a start bit before the LSB, and
a stop bit after the MSB. The start bit
is a logic low (0); the stop bit is logic
high (1). Figure 1 shows how an ASCII
“X” (0x58 hex or binary 01011000)
character is transmitted; notice the
sequence is reversed to 00011010.
In its simplest and most popular
use, the serial port is configured as
9600 bps, 8N1. That means the baud