Channels ▼

Al Williams

Dr. Dobb's Bloggers

Microchip USB: Part 1

March 19, 2012

For the last few weeks I've been skirting around USB, looking at USB to serial adapters and even talking to some off-the-shelf USB hardware using libusb. Of course, the next big step is to just go ahead and build something that actually attaches as a USB HID device. There's lots of support for this if you get the right microcontroller, and the list grows longer every day.

I finally decided to get started with the Microchip PIC solution. I happened to have some PIC 18F2550 chips handy and I recently wrote about my experiences with MPLAB-X on Linux and the ICD 3 programmer/debugger.

One nice thing about Microchip parts is the pin outs rarely change. The PIC 18F2550 has the familiar 28 pin footprint you expect from a PIC. A few pins are unique to the USB-nature of the part, of course. For example, port C loses a pin to the Vusb function and two more pins if you actually use the onboard USB peripheral.

Still, it was easy enough to connect the device to a breadboard for initial testing. I had previously picked up some nice USB breakout boards that let me hook a standard USB cable to a breadboard, but lacking that I'd have just cut a USB cable in half and soldered pins to the exposed wires. The USB board has five pins but one of them is the frame ground. The other four pins provide signal ground, 5V, and the two data lines (D+ and D-).

If you want to follow along, the circuit is fairly straightforward. I connected a 10K resistor between the 5V supply and pin 1 (the RESET pin). The 5V supply, by the way, comes straight off the USB cable. Pin 20 also connects to the 5V rail. The Vss pins (pins 8 and 19) go to ground, of course, along with the USB cable's ground pin. I also put a 20MHz resonator on the PIC's clock pins (pins 9 and 10).

The data sheet also tells you to bypass the Vusb pin (pin 14) with a .22uF capacitor. This is the 3.3V output provided for the USB transceiver and I didn't think it was that critical. I used two .1uF capacitors in parallel and decided that was close enough. You can optionally pull up the D+ and D- lines from Vusb (through resistors, of course), but I was trying to stay as simple as possible. The regulator, by the way, has to be enabled so if you aren't using USB you shouldn't need anything on this pin.

The other items I connected were pretty simple: a connector for the ICD 3 (I have a modular jack wired for just this purpose; the ICD 3 manual shows the connections for power, ground, RESET, RB7, and RB6 — you can leave RB3 disconnected) and a .1uF bypass capacitor between the chip's power lines (pins 19 and 20). I also wanted some simple I/O, so I put a 5V LED on pin 4 (RA2) and a switch with a 10K pull up resistor on pin 5 (RA3).

Below is a picture of the rat's nest — er — breadboard. No schematic, at least not this week, but if you grab the data sheet and follow the pin numbers you can hardly go wrong.

The remaining piece of the puzzle is software. You need three major components:

  1. MPLAB-X (see the video walkthrough)
  2. The MPLAB C18 compiler
  3. The Microchip USB Framework software

Last time I installed the USB framework it was a bit quirky, but I'm hopeful it will be better this time since it seems to be packaged a little better. The C compiler nicely integrates with MPLAB-X and I wrote a simple little test program to check out the hardware. The only thing the USB port does in this case is provide power (and note, do NOT check the box to have the ICD 3 deliver power to the device while you are using any kind of external power; the default is for the ICD 3 to remain passive, so you should not need to turn it off, but be careful not to turn it on).

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Video