Full USB tutorial for PIC microcontrollers

Discussion in 'Embedded Systems and Microcontrollers' started by adam555, Sep 28, 2014.

  1. adam555

    Thread Starter Active Member

    Aug 17, 2013
    858
    39
    Hi,

    I just got the PIC18F4550 in an attempt to use it for communications with a PC through its USB module, but I'm finding many problems just to get started.

    I looked on the internet for manuals and tutorials and found various; however, none of them are of much help for one reason or another. To start with, most wont even work in MPLAB X with the CX8 compiler, as they are based on the examples from the MCHPFSUSB 1.2; which was designed for C18 or C30 compilers. I tried to import and modify the demo projects, but after hours of dealing with a never ending number of errors and warnings, I got nowhere. And in any case, these tutorials are only meant to help you build your own bootloader demo board, or just test some CDC or HID app; none of them even attempt to explain what the necessary USB functions are or h0w to use them -they just tell you to upload a precompiled hex file and don't even touch the firmware.

    These are some of the tutorials I found; in case anyone is interested in trying them:

    Apart from the the MCHPFSUSB v1.3 and the MCHPFSUSB v2.2 I also downloaded the latest Microchip Libraries for Applications (MLA). I'm able to successfully compile some MLA apps -the ones that include the PICDEM FS USB demo board, as it has a PIC18F4550- but the problem is that it doesn't come with a tutorial or manual, just a reference guide; and in each project there are dozens of source files and headers.

    I guess I could spend the next month going through each project's files in an attempt to figure out what each function does and how it all works, but I'm sure there has to be an easier and faster way to approach this.

    Therefore, I would appreciate if anyone could direct me to an in depth manual or tutorial on how to use the PIC18F USB module, preferably using the MLA mentioned above, or explain what is the overall process and main functions that I need in order to get started.

    Thanks in advance,
     
    Last edited: Sep 30, 2014
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    If it was not for MPLAB X, CX32, the MLA, and whatever "Harmony" means I would have an answer for you, but I am still coming up to speed on the newest toolset. Ive tried to do this a few times in the past and somehow wind up using the same old and trusted tools.

    Under the old tools I could hijack the demo code to use as a base for my own useful apps. The sweet spots were the CDC communication app (RS-232 to USB) and the USB SD Card app. The former was easy to tease apart so the virtual COM port could talk to my app, and the latter for many apps where I wanted to use an SD card for storage but to also be able to offload data to a PC over the USB.

    In the old ways one could just look at the main() function and hack into "InitializeSystem();" or "ProcessIO();" to add my own app.

    The MLA examples seem to have similar hacking points but I can't even get those to load into MPLAB X for me, so I cannot say much about the newer ways.
     
  3. adam555

    Thread Starter Active Member

    Aug 17, 2013
    858
    39
    Thanks ErnieM,

    I guess that by old tools you mean MCHPFSUSB for the C18 compiler. I also found the MCHPFSUSB examples easier to follow than the MLA -and all the tutorials and examples I found on the net are based on it- but I was unable to download and install the C18 compiler and give it a try. I guess I would also need to find and install the previous MPLAB IDE.

    In any case, I just tested some of the demos on the MLA, which I have no problems compiling, but after connecting the circuit to the computer, and getting a couple of LEDs blinking, I always get the Windows error "USB devide not recognized"; so for now I can't even attempt to hack into the firmware.
     
    Last edited: Sep 29, 2014
  4. adam555

    Thread Starter Active Member

    Aug 17, 2013
    858
    39
    Does Microchip offers the CCS C and the C18 compilers free for downloading, or you have to buy them?

    I just installed MPLAB IDE 8.70 but neither were installed. I looked in my PICKit 2 starter kit CD and it brings a demo version of CCS C that will just work with the PIC16F887 from the demo board. Can't find any CCS C downloads on the Microchip website.

    Regarding the C18, on their website they only offer updates for download; which I guess implies you need to have it installed already.
     
  5. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,398
    497
    MPLAB® C Compiler for PIC18 MCUs (C18)

    "Standard-Eval Version
    The Standard-Eval Version is free! It has all the features of the full compiler and libraries. After 60 days, the optimizations related to procedural abstraction and to the extended instruction set of the newer PIC18XXXX devices will be disabled. Code compiled after the expiration date will function but may occupy more memory space.

    Note that this product was previously referred to as MPLAB C18. Previous upgrades may be available on the archive page."

    http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=SW006011
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
  7. adam555

    Thread Starter Active Member

    Aug 17, 2013
    858
    39
    Thanks for the links,

    I gave the MCHPFSUSB a try with the C18 eval version in MPLAB 8.70 and I'm still getting the same result as with MLA: 2 LEDs blink when I connect the circuit to the USB cable, and then I get the error message "USB device not recognized". It also doesn't ask me for the drivers; it says that I should change the device because it's malfunctioning.

    It might have something to do with the fact that I'm using a 16Mhz crystal instead of a 20Mhz; though I changed the PLL prescaller in the configurations bits to 4 instead of 5, which shouldn't make a difference since the result is the same 4Mhz input for the reference clock.

    Is there anything else I should change to use a 16Mhz crystal. I ordered the 20Mhz ones, but they won't arrive until next week.
     
Loading...