that require the use of PPS (Peripheral Pin Select).
We can generate code with the Code Configurator
until the cows come home. If the code we’re producing
doesn’t match our RN4020 hardware, it is totally useless.
So, let’s draw up our plan schematically and set up our
hardware using the Configurator.
System Setup
Schematic 1 tells us that pins RB5 and RB7 are
receive and transmit pins, respectively. Let’s use that
information to initialize the PIC16F1619’s EUSART.
However, before we set up the EUSART, we need to take
care of the system setup first. We will run at 16 MHz
using the PIC’s internal oscillator. The PIC’s configuration
fuses are set using the Code Configurator. The fuse panel
is shown in Screenshot 1. What you don’t
see in Screenshot 1 is my personal
selection of some configuration fuse
particulars. The only fuse that is critical to
be configured is the LVP Enable, which
should be turned ON.
EUSART Setup
Now that we have established a CPU
clock frequency, we can move on and
configure the PIC’s EUSART. The RN4020
operates at a baud rate of 115200 bps. So,
as you can see in Screenshot 2, we simply
relate our baud rate desires to the MPLAB
Code Configurator. While we’re at it, we’ll
lay the ground work for the EUSART
interrupt mechanism. In Screenshot 2, I’ve
also enabled EUSART interrupts and set up
a pair of 64-byte receive and transmit
buffers. Being able to write to the EUSART
using printf statements is a good thing. So,
to enable the printf functionality, I’ve
checked the Redirect STDIO to UART
check box.
GPIO Setup
In my opinion, this is the coolest
feature of the Configurator. When creating
new project code, I spend LOTS of time
manually defining I/O pins and creating
their aliases. As you can see in Screenshot
3, the Code Configurator has assisted in
identifying the EUSART pins, as well as all
of the RN4020 interface I/O pins.
The Curiosity dev board has a trace
running from the PIC’s RC0 pin to the
RN4020’s WAKEHW pin. If you don’t
want to cut that trace on your Curiosity board, you can
assign the WAKEHW pin to RC0 and forego using the
optional RTS pin. I cut the WAKEHW trace on the board
and wired in the RTS signal.
Wiring In the RN4020
The RN4020’s TX and RX pins are already connected
correctly by existing traces on the Curiosity. The TX and
RX lines are shared with the click mikro BUS socket. So,
you can’t load the socket and use the onboard RN4020 at
the same time. If you want to use the onboard RN4020
and a click module simultaneously, you’ll have to isolate
the onboard RN4020 by cutting the traces that are
common to the click mikro BUS socket.
I like wire wrap. If you use it carefully, you can save
56 December 2015
Post comments on this article and find any associated files and/or downloads at www.nutsvolts.com/
index.php?/magazine/article/december2015_DesignCycle.
■ Screenshot 1. This is a capture of the MPLAB Code Configurator System
configuration screen. All of the PIC16F1619 configuration fuses can be
configured from this panel (configuratively speaking).
■ Screenshot 2. All of the pain of setting up an EUSART has been removed
by this window. We need only tell the MPLAB Code Configurator what we
want the EUSART to do and how fast it should run. To utilize the XC8 C
compiler’s printf function, we must check the Redirect STDIO to USART
check box.