Serial Communication MPLAB® Xpress

 Objective

Serial Communication - MPLAB® Xpress Example

In this project, a serial communications link is established with the PIC16F18855 MCU populating the MPLAB Xpress Development Board and a host PC. This communication is enabled by a PIC18LF25K50 MCU which is also populated on the Xpress board and is configured for two different USB classes to perform the following tasks:

  • Configured using the USB Mass Storage Device (MSD) Class, receives HEX files from the host PC and then programs the PIC16F18855 using Microchip Technology’s In-Circuit Serial Programming (ICSP™) technology
  • Translates EUSART data transmissions from the PIC16F18855 and transmits over the USB connection to the host PC using the USB Communications Device Class (USB CDC)

Using the latter CDC configuration enables the PIC16F18855 to send and receive information through the PIC18LF25K50 to an available USB port on a host computer. Terminal emulation software running on the host computer connects to the associated COM Port and can then be used to display information from the PIC16F18855 or allow the user to send commands back to the Microcontroller.

figure1.png

 Materials

Hardware Tools (Optional)

Tool About Purchase
Xpress-50px.png
MPLAB® Xpress
Development Board

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® Xpress
Cloud Integrated Development Environment

Exercise Files

File Download
Installation
Instructions
Windows Linux Mac OSX
Project and Source Files

 Procedure

The PIC16F18855 EUSART peripheral connects on pins RC1 (TX) and RC0 (RX) to a PIC18LF25K50 configured to operate as a CDC USB device to translate the EUSART message for transmission over the USB protocol to a host computer COM Port.
The project uses:

Windows users need to install the appropriate signed drivers in order to use the CDC configuration on the PIC18LF25K50 as detailed below. Linux® and MacOS® users may skip over these two steps.

  1. The Windows signed drivers can be downloaded directly here.
  2. Once the inf – Composite Devices.zip has been downloaded, extract the files to the C:\DRIVERS\WIN directory.

To follow along with these steps, MPLAB Xpress should be open and the user should be logged in so that the MCC plugin can be used. The setup is described in the Setup and Installation section of this training module. You should see a screen similar to the one shown here.:

figure2.png

1

Task 1

The MPLAB Xpress Development should be connected to an available USB port on the host computer through a USB cable to the micro B connector on the board. Drivers should install successfully the first time the board is connected and may take a minute or so. The connection is shown in the picture. No other components are required.

figure3.png

2

Task 2

Create a new project in MPLAB Xpress for a PIC16F1855 using the MPLAB Xpress Development Board. Instructions are below if this is your first project.

3

Task 3

Open the MPLAB Code Configurator (MCC) under the Tools > Embedded > MPLAB Xpress Code Configurator menu of MPLAB Xpress.

figure4.png

A window will appear showing three steps. If you need the latest version of Java you can click on step one, otherwise, click on step two to open the MPLAB Xpress Code Configurator.

figure4_1.png

A file will automatically download in your browser similar to the picture shown. Click on that file to open it. This is a java application that will launch the MCC.

figure4_4.png

The process can take several seconds depending on your internet connection speed. Several windows may appear asking if you want to run the program. When the process is complete you will see a new screen appear, separate from the MPLAB Xpress IDE, that is the MCC control screen. In this screen, you can select peripherals for your project, set up the oscillator system and other configuration settings, and input and output selections for your device. When all this is completed you can generate project code including a main.c file. All these generated files will be included in your MPLAB Xpress project.

figure4_3.png

4

Task 4

In the open MCC window, the default parameters for the System resource can be used but you will need to add the EUSART peripheral to this project and set up the pin connections for the communication.

figure5.png

In the Device Resources area scroll down to locate the EUSART peripheral and expand. Double-click on the EUSART to add the peripheral to the Project Resources.

The Enable EUSART box should be checked. Enable Transmit should also be checked. The Baud Rate dropdown should be set to 19200. Finally, the Redirect STDIO to USART should be checked since this project will be using PRINTF statements to send data from the EUSART peripheral.

figure6.png

The setup in MCC should look like this:

System

  • System Module
  • Interrupt Module
  • Pin Module

Peripherals

  • EUSART

5

Task 5

In the Pin Manager section, connect the EUSART TX signal to pin RC0, and the RX signal to pin RC1, by clicking on the blue unlock button. Doing this turns it to a green locked symbol for the associated signal row and pin columns as shown below:

figure7.png

6

Task 6

Click the Generate button in MCC to create the appropriate header and source files for this configuration. A main.c file will also be generated for the project.

figure8.png

Upon successful code generation the “Generation Completed” notification should appear. Select OK to close the window.

figure9.png

New MCC Generated header and source files should now be present in the Project window of the MPLAB Xpress IDE including a new main.c source file.

figure10.png

7

Task 7

Click on the main.c source file in the Project pane to open the file and scroll through the code to locate the // Add your application code comment inside of the while(1) loop inside of the main().

figure11.png

At this point add a simple printf statement that will be used to execute a transmission over the EUSART and eventually display on the host computer. A simple statement enclosed in double quotes is all that is needed.

printf("Hello from MPLAB Xpress! \n \r");

You may wish to add a newline (\n) and a carriage return (\r) commands as shown.

figure12.png

8

Task 8

Compile and download the project HEX file by clicking on the Make and Program Device button at the top of the MPLAB Xpress IDE.

figure13.png

9

Task 9

Program the MPLAB Xpress board by dragging the project HEX file from the downloads section of the browser and dropping the file on to the XPRESS drive.

figure14.png

The Programmer LED on the Xpress board should quickly flash from green to red and then back to green indicating that the HEX file was successfully programmed to the PIC16F18855.

figure15.png

10

Task 10

Open a terminal emulator program on the host computer and select the COM port associated with the MPLAB Xpress board. In this example a free program called TeraTerm is used. Note that the COM port number will probably be different from that shown below.

figure16.png

Configure the terminal emulation software to communicate at the 19200 baud rate that was configured earlier in the project when configuring the EUSART in MCC.

figure17.png

 Results

Once communication is established, the terminal window should display the text enclosed in the printf statement added earlier in the project.

figure18.png

 Analysis

The example shows how to perform one-way communication. The Xpress board sends the data as ASCII characters that are then displayed in the terminal window as text.

 Conclusions

This project can be the basis for building a two-way communication project where data entered in the terminal window is sent back to the Xpress board and the data can be used in another algorithm.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.