# Implementing USB On PIC24

We want to implement USB on our PIC24 based embedded system.

Hardware: All done
Firmware: USB part is currently Non-existent
My role: Make it all work
Questions: The protocols are very complex

Please point me to relevant sources of info.

The specific chip is: PIC24FJ256GB210.
It will be a "device", and I don't think it will ever be a host, even a host-to-go I have previously spent time at these places...

Microchip's forums, here: http://www.microchip.com/forums/

The USB Implementers Forum, here: http://www.usb.org/developers/docs/

Jan Axelson's site, here: http://www.lvr.com/usbc.htm and purchased her book "USB Coomplete"

The firmwware in the embedded device is what I need to write. The protocol is what I need to research the most. Pointers invited and welcome.

Protocol, Protocol, Protocol; that is what nobody can explain.

• What do you need it to do? If a serial channel would be workable, USB-serial is generally fairly simple, probably has drivers, and lots of examples. Also many other common USB peripheral types - keyboards & mice, mass storage, etc. You'll need to decide what existing or custom protocol you need before you can implement anything. Apr 29, 2013 at 19:26
• The box uses BlueTooth, but as you are probably aware, that can go to pot very quickly on a PC. For that reason, the boss wants me to utilize the USB port as a backup. Apr 29, 2013 at 20:18
• Reason #2: we want to use the USB port to charge the battery on the device Apr 29, 2013 at 20:19
• You've still failed to specify what sort of communication you want to achieve on the USB port. You will get absolutely nowhere until you determine your precise requirement. Apr 29, 2013 at 20:21
• Finished 2 chapters in Jan Axelson's book. Is this going to be a new career ? I swear a person could do nothing but learn new USB rules and regulations for the rest of his life May 13, 2013 at 14:50

The PIC24 has a decent couple of demos in the Microchip Libraries for Applications (MLA). For help on the circuitry necessary, check out the microchip pictail board and the explorer 16 board. All microchip demo boards include a full set of schematics to help you get off the ground running. The usb protocol is generally taken care of for you in the USB stack that's included in the MLA. The configuration is mostly accomplished by setting up your USBDescriptor.c file (see the included demos in MLA and the Microchip USB Device Firmware Framework User's Guide).
All that's usually required code wise after that's done that is to call USBTasks() in a main loop after calling USBInitialize once before your main loop. Then it's a matter of sending and receiving USB data which will depend on how you've configured the stack.