CREATING A VIRTUAL SERIAL
PORT WITH THE 32-BIT MICRO
EXPERIMENTER
BY THOMAS KIBALO
Discuss this article in the Nuts & Volts forums at
http://forum.nutsvolts.com.
The Universal Serial Bus (USB) has made it very simple
for end-users to attach peripheral devices to a PC, all but
eliminating the myriad of different interconnects that
used to be necessary. One such traditional legacy
interconnect that is becoming increasingly rare is the
RS-232 serial COM port. In fact, many modern laptop
computers no longer have one.
In the Oct ‘ 11 Experimenter article, we stated that
legacy communications (i.e., serial port with a PC) are
still widely used with microcontrollers. This presents an
issue to those applications still needing a serial port on
a PC. No worries! With the 32-bit Micro Experimenter,
Microchip’s USB Firmware stack, and its USB device
interface we can provide all the required functionality
for a virtual serial port without any additional hardware.
This USB serial port is designated as a CDC
(Communication Device Class).
We will explore in detail how the CDC can be used to provide virtual serial communications between a PC and the Experimenter. For demos, we will use the PS/2 keyboard, a rotary knob, and analog data sensor values
as data sources to the PC. We will also make use of the PC
and its keyboard for terminal operations. We will embark
on a somewhat deep journey into Microchip’s USB
framework, but I promise it will be worth it. After reading
this article and trying the experiments, you will have an
understanding of how to use the Experimenter to emulate
a serial port with USB. Again — as in all articles in this
series — a general familiarity with the C language is required.
The Experiment Demos
and Setup
FIGURE 1. Experimenter as a virtual port.
FIGURE 2. Block diagram.
drivers are in place already).
• No special external hardware chip sets are required, like
FTDI (uses internal USB peripherals within the PIC32).
• Firmware modifications to the existing application code
are minimal; only small changes are needed for the
virtual serial port and they are provided as part of the
USB firmware framework written in C.
We will cover four distinct demo experiments that
may be of direct use in your future projects:
The demo applications show how the PIC32 family
CDC serial function driver provides a virtual UART to
emulate a legacy serial COM port to the host PC. This
approach will illustrate several advantages to the user:
• It has little or no impact on the PC software (since
• PS/2 Keyboard to USB Demo – This demo uses data
originating via a PS/2 keyboard connected to the
Experimenter to display keystrokes both on the PC, as
well as on the Experimenter Universal Graphics Module.
Uses a Mini-Kit module.
• PC to Experimenter Display USB Demo — This demo