PIC 18F2550 USB help

Discussion in 'Embedded Systems and Microcontrollers' started by ozirock, Sep 20, 2012.

  1. ozirock

    Thread Starter Member

    Jan 13, 2011

    I've spent ages looking through page after page about using USB on the PIC 18F2550 and my head is wrecked with it!! I've always worked with assembly programs with other PICs I used such as the 16F627, 16F886 etc so I never had any difficulty with uart in assembly. But moving to the 18F2550 I'm struggling to understand how it works so here are a few questions from what I've read.

    1. I have to use C programming to use USB, there is no simple assembly routine like UART?
    2. I have to use a bootloader?
    3. When I have the bootloader on the PIC I still have to use C code if I want to use USB communication?
    4. Can someone show me an example of code to for example send 8 bit over USB and have it displayed on a port, something that I can understand whats happening.

    I have an ICD2 so I'm confident I can program a bootloader without any problem. Any advice would be much appreciated, I'm just getting overwhelmed by all the different explanations how to do it after a google search, every man and his dog seems to have made a bootloader!!
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    I think C is the best option. Have you poked around the Microchip site for examples. No you do not have to use bootloader if your ICD2 support your PIC. However I think some of the USB examples on the Microchip site is a bootloader. But you will also find some USB Serial port on PIC examples. Perhaps these will be the best starting point
    Edit I think you should start here http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en537044
    Last edited: Sep 20, 2012
  3. nigelwright7557

    Senior Member

    May 10, 2008
    Do yourself a huge favour and visit www.waitingforfriday.com
    He not only gives circuit diagrams but supplies software for PIC and PC.
    It is seriously handed to you on a plate.
    I have done two projects now using his hardware and software and it works first time !
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Well hi there.

    C is much much better and ultimately less confusing. If it's time to do some USB then it's time to learn at least some C.

    Absolutely not! In fact that's a complicated program to create, as sometimes it has to work as a USB bootloader, sometimes as your USB application.

    No, the bootloader should load whatever hex file you hand it. While I've never loaded an assembly program with a bootloader, it should be fine. I expect you would have to adjust the linker or such to shift the code image away from where the bootloader lives.

    The C apps I've done need a custom linker for bootloading.

    You may already have them. Microchip gives away several very handy example programs for several series of parts (PIC18, ds24,ds32, PIC32) that can be easily adapted for other programs. They are your complete trustworthy friends here to begin your own development projects.

    My two particular favorites are the "USB Device - CDC - Serial Emulator" and the "USB Device - Mass Storage - SD Card reader"

    A CDC (communications device class) emulator makes your USB PIC look like a serial port to the PC, meaning lots of legacy programs (even windows HyperTerminal) can talk to your PIC device. While you can add a full RS-232 interface and talk to some other third device (PC <-> PIC <-> {some terminal or other PC) it is simplest if you just connect the RX and the TX of the PIC together, so it just echos anything it is sent.

    You send a packet of information over the USB to the PIC, it resends this packet on it's serial port. When the PIC receives data on it's serial port, it sends it back to the PC over the USB. This is controlled inside a routine called ProcessIO." You are free to intercept data inside this routine and just redirect some to any I/O port to control the pins. In fact, I've done this for a simple digital control device.

    You'll need a few downloads to do this:

    Microchip Libraries of Applications

    MPLAB C Compiler for PIC18 MCUs

    I assume you already have MPLAB. (I've yet to switch to MPLAB-X.)

    The example doesn't include your PIC18F2550 as one of the supported devices, so you'll have to edit one of the hardware profiles to meet your hardware. I can help there if you post or link to a schematic of your board.
  5. ozirock

    Thread Starter Member

    Jan 13, 2011
    Thanks for all the replies guys. I was searching different things as I read your comments and stumbled across this assembly code http://jap.hu/electronic/pic18-usb.html he uses a bunch of macros and stuff which I'm not familiar with. I didn't have time to read through it but I was able to compile it and download it to a 18F2550 without mplab reporting any errors so I'm now sure my ICD2 can program my chip. The program didn't work mind, it turned RB4 high while I was expecting it to flash an LED on RA1 or RA0 I forget now. But anyway thats beside the point it is clear from reading your posts that C is the way to go without a doubt.

    @t06afre : USB serial port is exactly what I'm looking for, effectively have the pic show up as if I had plugged in an FTDI cable. Probably a simplistic use for the USB function on the PIC but it would suit my needs perfectly.

    @nigelwright7557 : Thanks for the link, the "Building a PIC18F USB device" article should help me along nicely but as well as that there are plenty of other interesting articles, it's a great resource to have.

    @ErnieM : Yes you assumed correctly I do have mplab installed. Hopefully I'll get a chance to look through the Microchip Libraries of Applications over the weekend and install the C compiler, it will probably take me a little while to get my head round that. I'll post back if I'm having trouble with the hardware profile, I've yet to settle on a circuit I will probably try the circuit suggested by nigelwright7557 to start with.

    Thanks for all the suggestions guys I've a much better idea of where to start now :)