Electronic – Tutorial for USB communication with a PIC18F4550 using CDC framework

communicationpicserialusb

I am trying to perform USB communication from the PC to a PIC18F4550 microcontroller using the Microchip PIC18 USB CDC(Communication Device Class) Framework which essentially makes the PIC18, connected to the pc through the usb cord to the usb port of the pc, appear as a vritual COM port on the PC. This gives me the ease of sending the data as if I was sending it to a serial port on the pc side and removes the hassle of using a usb to serial converter.

Now the problem is that the demo project provided by Microchip is written so that it can be burned on different devices, with different circuits, or with different conditions – that makes it large, and for me at least, harder to understand. If someone could hopefully just provide a working code with minimal comments for this microcontroller or something similar OR link me to a good tutorial, it would make my life MUCH MUCH easier

Thanks.

Best Answer

I have no experience with the CDC but I have some with the MSD class. Some steps I did and may be useful for you. First, let's create a stand alone project:

1) I assume you have downloaded and installed the MAL (Microchip Application Libraries). Copy to your example directory the following files: usb.h, usb_ch9.h, usb_common.h, usb_config.h, usb_device.h, usb_device_local.h, usb_hal.h, USB PIC18.h, usb_function_cdc.h, usb_function_cdc.c and add them to the MPLAB X project. Remove the libraries from the MPLAB project.

2) Compile it, link it, and see if it's still working ok.

3) Using MPLAB X, remove all the code lines that are grayed in the #ifdef or #else preprocessor blocks. That is, remove all the code intended for other architectures that are not intended for a PIC18F45XX.

4) Repeat 2.

5) If you start studying the code now, you'll notice that it's much simpler than what you thought in the beginning, and you will have much more control over you project.

Hope this helps.