### PIC18 USB-UART Firmware on RN4020 PICtail

### Firmware Rev. 2.0

Overview:

The PICtail board has a PIC18 USB-to-UART serial bridge on the board to enable easy serial connection to a PC over USB. While in USB-to-UART Bridge mode, the board can be plugged into a PC that supports serial COM ports. When plugged in over USB mini-B receptacle J5 to a PC, the board enumerates as a serial COM port. A terminal emulator application on the PC can be used to open the COM port. On the opened COM port, the standard RN4020 commands can be issued when the RN4020 is in Command mode, or to transfer data when it is in Microchip Low Power Data Profile (MLDP) mode. For more information on the UART configuration and the commands available for RN4020 module, refer the ‘RN4020 Bluetooth Low Energy Module User’s Guide’.

The USB-to-UART Bridge mode also enables a simple command shell running on the USB-to-UART Bridge that is used to control the GPIOs on RN4020 through the PIC18. Typing ‘$$$’ with a carriage return on the terminal emulator will enter the PIC18 command shell. The PIC18 command shell supports the commands in the table below. Typing ‘$$$’ with a carriage return a second time on the terminal emulator will exit the PIC18 command shell. There is a one second guard band duration for both entry into and exit out of the command shell. Command shell is entered or exited only if there is no data transfer during the duration of the guard band.

The firmware also enables the RN4020 auto demo mode in the PIC18 command shell. This can be used with ‘RN4020 Demo’ Android app to transfer data over the Bluetooth Low Energy connection between RN4020 PICtail and the Android device
running the ‘RN4020 Demo’. Refer to the readme file available for the ‘RN4020 Demo’ Android app for installation and usage instructions.

RN4020 Demo App for Android: http://ww1.microchip.com/downloads/en/DeviceDoc/rn4020_demo_android_app_v1.0.zip

v2.0 Commands Supported | Description
I#X,YY | Sets or Clears the IO port A/B/C on PIC18
I@X,YY | Sets the direction of the IO port A/B/C on PIC18
I%X | Reads the IO port A/B/C on PIC18
T,S | Starts RN4020 auto demo mode
T,E | Stops RN4020 auto demo mode
H | Command help
V | Version of the command shell
Legend: X – A or B or C; YY – Hex byte value;

The ‘rn4020_pictail__pic18_usb_uart_firmware’ workspace contains the firmware for the PIC18 USB-to-UART serial bridge that enables the above functionality. The workspace can be found in the ‘\USB\rn4020_pictail__pic18_usb_uart\Firmware’ folder. The precompiled hex file is available in the ‘precompiled_hex’ folder. It uses the ‘Device - CDC - Serial Emulator’ workspace available in the Microchip Libraries for Applications (MLA) as base.

For additional information on RN4020 PICtail Plus board, refer the ‘RN4020 PICtail Plus Board User’s Guide’.

All relevant information and documentation on RN4020 can be found in the following web link: http://www.microchip.com/RN4020

Running the Demo:

Programming/Debugging

1) Remove jumper JP1 on the RN4020 PICtail board to select USB-to-UART bridge mode.

2) Connect the mini-B end of the USB mini-B cable to the J5 USB connector on the RN4020 PICtail board.

3) Connect the type-A end of the USB mini-B cable to a PC.

4) Open the MPLABX workspace available ‘\USB\rn4020_pictail__pic18_usb_uart’ folder.

5) Compile and program the PIC18 USB-UART firmware ‘rn4020_pictail__pic18_usb_uart_firmware.X’ workspace in ‘rn4020_PIC18F25K50’ configuration.

Running Demo

1) Remove the jumper from JP1 on the RN4020 PICtail board to select USB-to-UART bridge mode.

2) Connect the mini-B end of the USB mini-B cable to the J5 USB connector on the RN4020 PICtail board.

3) Connect the type-A end of the USB mini-B cable to a PC.

4) The PC will automatically install the required serial drivers. If the drivers are not installed automatically, the drivers can be found inside the ‘inf’ directory or they can be downloaded from the below link and installed manually.

RN4020 PICtail serial port driver: http://www.microchip.com/DevelopmentTools/ProductDetails.aspx?PartNO=rn-4020-pictail

5) After successful installation of the drivers, the board enumerates and a serial COM port will be associated with the PICtail board.

6) Open the COM port in a serial emulator terminal with the following serial port settings: 115200 bps; 8 data bits; 1 stop bit; parity none; rts/cts flow control

7) On the terminal, any of the RN4020 commands can be issued directly to the RN4020 module connected over UART. For RN4020 commands and their description refer ‘RN4020 Bluetooth Low Energy Module User’s Guide’ .

8) On the terminal, ‘$$$’ can be typed followed by carriage return to enter the PIC18 command shell. Refer the ‘RN4020 PICtail Plus Board User’s Guide’ for the available commands on the PIC18 command shell.

9) Issue any of the commands supported by the PIC18 command shell.

10) On the terminal, ‘$$$’ can be typed followed by carriage return again to exit the PIC18 command shell.

Required Hardware

RN4020 PICtail Plus (rn-4020-pictail)

## PICkit 3 In-Circuit Debugger (PG164130)

Trademarks

The Microchip name and logo, the Microchip logo, MPLAB, and PIC are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

PICDEM and PICTail are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries.

SD is a trademark of the SD Association in the U.S.A and other countries

Microsoft, Windows, Excel, and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.