function simply toggles the two LEDs on the Experimenter.
If the system is operating properly and ProcessIO() is non-blocking, then these LEDs should be blinking at a fairly
regular rate. If ProcessIO() blocking occurs, then the LEDs
may stop blinking or blink fairly unevenly.
Keep in mind that the blinking only starts once the
Experimenter has been hooked up to the PC and is
registered with the PC driver (USB jargon “enumerated”).
4. The Virtual UART API
The CDC class within the Microchip USB stack
supports the virtual UART API. These are the five
functions that you will use in your ProcessIO(). By
invoking the functions within this API, users can emulate a
UART that both transmits and receives data to a PC. We
will look at this API more carefully in the demos. The
complete API is as follows. The choice of selecting which
function in the API to use depends on several factors in
the user’s application. For instance:
• Is the string of data null-terminated?
A more detailed description is covered here:
• mUSBUSARTis Tx TrfReady() — Is the driver ready to
accept to accept a new string to write to USB?
• putrsUSBUART (“string”) — Write a null-terminated
string from program memory to the USB.
• putsUSBUART (“string”) — Write a null-terminated
string from data memory to the USB.
• mUSBUSARTTxRom (data from flash, length) — Write a
string of known length from program memory to the USB.
• mUSBUSARTTxRam (data from ram, length) — Write a
string of known length from data memory to the USB.
• getsUSBUSART (receive buffer, length) — Read a string
from the USB.
5. PC Serial Port Setup
Finally, the last component is setting up the PC for a
serial port. The port will extend the existing COM port
portfolio on a PC host to a new COM port. In our demo, we
will configure the serial port at a default 9600 baud, eight-bit,
no parity, one stop bit, and with no hardware handshake
(9600N81). Other configurations are possible. A block
diagram of the Experimenter to PC setup is shown in Figure 9.
An install process is required for the PC terminal to register
the Experimenter USB as a virtual serial COM port on the PC.
Once demo firmware is programmed into the Experimenter,
the user should connect the board to the PC USB and
follow the on-screen instructions to install the default (
OS-provided) driver on the PC. The demo application will show
up as a new COM port (number assigned by the OS).
Select this COM port from within the PC terminal
emulator application. A number of PC terminal
applications can be used like Hyper Terminal or Tera Term,
FIGURE 8. CDC virtual UART API.
FIGURE 9. PC serial port setup.
FIGURE 10. USB
or use a Visual Basic (VB) Net 2008 GUI that is available
with the demos for download. The VB GUI application
allows communication with a serial port. However, the VB
version will require you to download and install Visual Basic
Express 2008 edition which is free. Whatever your selection
of terminal application is, a registry file or INF needs to be
installed. The INF file is also included with the demos.
Once you connect your Experimenter USB to the PC,
the Windows OS requires a software driver be installed for
each new COM port. The Windows OS “Install Wizard”
offers two possibilities: searching the Web or browsing
your computer for the correct driver. The optimal choice is
to browse your computer and navigate to the downloaded
demo folder where a copy of the INF file is located. Select
this driver and direct Windows to do the install. These steps
were covered and illustrated in an article in the Oct ‘ 11 issue
entitled “Legacy Communication using the 32-bit Experimenter.”
Virtual Serial Port Demos
Now that we understand all the important theory and
technical considerations, let’s apply it. In all the following
examples, the focus will be on ProcessIO(). This is where
the magic happens. For the most part, all the rest of the USB
project file is similar. Where any new files are introduced,
they will be discussed. As mentioned earlier, in all examples
we will assume the use of the Universal Graphics Card. This
is an Arduino compatible interface board that plugs into
the Experimenter. Also, when the rotary encoder or PS/2
keyboard is used, the Mini-Kit is assumed. Again, a hook-
February 2012 47