HP16C results in an error percentage of -0.22%. That should
be good enough to reliably get bits to and from the Tera
Term Pro application running on the Lenovo NetBook.
Getting the baud rate value right is only part of
what we need to do to bring up a working RS-232 link.
The µOLED-128-G1 wants to see RS-232 packets that
contain eight bits of data, a single Stop bit, and no
Parity bit. That’s basically what the UARTSetLineControl
function arguments are telling us will be configured.
Take another look at Screenshot 1. However, this time
give your attention to the U2AMODE SFR (Special
Function Register). We’re interested in bits 0, 1, and 2.
Bits 1 and 2 — the PDSEL (Parity and Data Selection)
bits — are clear which represents eight-bit data packets
with no parity. Bit 0 is the Stop Selection bit and it is
also clear, indicating 1 Stop bit is appended to each
eight-bit data packet.
At this point, we should be good to go with UART2A.
All that’s left to do is enable the UART module which
we do by calling the UARTEnable function. Bit 15 of
the U2AMODE SFR is the UART2A Enable bit which
shows as set in Screenshot 1. When set, the UART2A
Enable bit turns UART2A “ON” and places the UART2A
pins under the control of the UEN (UART2A Enable)
bits. The UEN bits are located at bit positions 8 and 9
in the U2AMODE SFR. The default condition of the
UEN bits is cleared which enables the U2A TX and RX
pins, and disables the UART2A RTS and CTS pin
functionality. This configuration is desired as we are
planning to use the I/O pin that doubles as UART2’s
RTS signal for the µOLED-128-G1 ‘s RESET pin driver.
Look away from UART2A’s SFRs for a moment and
focus on the U2BMODE SFR value. The only bit that is
set in the U2BMODE SFR is the FRZ bit which is invoked
during Debug mode to indicate that the operation is
frozen when the CPU is in Debug Exception mode. In
that I was stopped in Debug mode when I snapped
Screenshot 1, the state of the FRZ bit is logical. I point
this out as the FRZ bit in U2AMODE is also set and has
nothing to do with the normal operation of UART2A. Note
also that UART2B is OFF, as bit 15 of U2BMODE is clear.
The UART_RX and UART_TX arguments of the
UARTEnable function affect bits 10 and 12 of the U2ASTA
SFR. Bit 10 reflects the ON state of the UART2A
transmitter, while bit 12 displays the ON status of the
UART2A receiver. Both bits 10 and 12 are set indicating
that the UART2A transmitter and receiver are online.
The PmodRS232 connects to the
PIC32MX795F512L’s UART2A interface on its TTL side
and channels through to the Tera Term Pro application
on the RS-232 side. UART2A is configured and ready to
go. So, let’s insert this code snippet into the ProcessIO
function of the MCHPFSUSB Framework HID-class
rxdata = UARTGetDataByte(UART2A);
SCREENSHOT 1. A PIC32MX Family Reference
Manual and the bits in the PIC32MX795F512L’s SFRs are
all we need to figure out what’s going on with the
PIC32’s six UARTs.
Do you see what the code snippet is doing? Let’s
talk through it. If valid data has been received by
UART2A, it is transferred from the UART2A receive
buffer into the eight-bit rxdata variable. If the UART2A
transmitter is idle, the byte in the rxdata variable is
loaded into the UART2A transmit buffer. Upon seeing
the incoming byte, UART2A serializes and transmits the
byte. You got it! It’s a character echo function. The
good news is that I was able to echo characters from the
Tera Term Pro session, through the PIC32MX795F512L,
and back to the Tera Term Pro window.
With the PIC32 UART2 module operation verified, I
rewired the PmodRS232-to-PIC32MX795F512L interface
and added a two-position DIP switch (SW1) to isolate
the UART from the PmodRS232 and µOLED-128-G1
serial interfaces. Note that the PmodRS232 and µOLED
interfaces are always electrically connected. To use the
Pmod/µOLED-128-G1 connection, both poles of SW1
must be in the OFF position which isolates the UART2
interface. With the PIC UART2 out of the circuit, we are
able to communicate with the µOLED via RS-232. This
arrangement allows us to load a PmmC or control the
µOLED from a PC serial port. When both poles of SW1
are in the ON position, the µOLED-128-G1 is under the
influence of the PIC32MX795F512L. The PmodRS232
module should not be mounted in its socket when SW1
is allowing an electrical connection between the UART2
and the µOLED.
Driving the µOLED with the PIC32 is a piece of
cake. The µOLED-128-G1 requires at least one second
of quiet time when you power it up. The power-up
delay allows the µOLED-128-G1 to initialize its internal
graphic memory and display registers. We are not
allowed to communicate with the µOLED during this
one second power-up delay time. Once the µOLED-128-
SERVO 02.2010 41