PIC32MX: USB Communication with a PC

From Mech
(Difference between revisions)
Jump to: navigation, search

Revision as of 20:35, 15 February 2010


Original Assignment

Do not erase this section!

Your assignment is to set up the PIC32 to send and receive data with a PC using the USB communications device class (USB CDC).

This type of communication will allow you to talk to a virtual serial port on a PC, just like using the RS232 cable, except you will communicate with the USB cable that powers your PIC32 and achieve faster communication than you could with the RS232 cable.

Use the example projects in the "Microchip Solutions/USB Device - CDC - Basic Demo" and "Microchip Solutions/USB Device - CDC - Serial Emulator" folders as guides.

Send 1000 bytes of data to your PC from your PIC32 and have your PC echo them back to the PIC32. How long does it take? Does it always take the same amount of time? What if you change to a different (faster or slower) PC?


In the past, the RS232 cable has been used to communicate with a PC. However, the PIC32 is capable of communication through the USB cable as well. This form of data transfer is preferable for a number of reasons. First, the circuit is much simpler (in our case non-existent). Second, the speed is significantly faster.

The average speed of the RS232 tops out at about 100 kbs. However, the program we wrote clocks the USB transfer at an average speed of about 2 mbs, which is about 20 times as fast.

In order to clock the USB transfer rate, both C code and MATLAB code were required. Both codes can be found below.

The output of the MATLAB code should read as follows:

"The average bit rate was 15330.950 kbits/s There were a total of 0 errors during the transmission"


There is no circuit required for USB communication with a PC. The USB cable that powers the PIC is the same that transmits data in and out.


Where possible, make it a single piece of well-commented cut-and-pastable code, or at least make each function that way, so others can easily copy it. Most comments should be in the code itself; outside the code (on the wiki) should only be explanatory comments that are too cumbersome to include in the code.

Two codes can be found below. The first if the C code

Personal tools