It seems that every little widget (processor or whatever) I work with has a serial port on it, which is extremely handy for printing status and debugging information, etc. These serial ports are of course “TTL” level, which means they’re at the level of whatever the part’s I/O voltage is, usually 3.3V but not always. The question becomes, how do we connect this to a PC so we can view the widget’s output in our favourite terminal program?
The solution used to be simple – use a MAX232 part (or similar) and a DB9 connector. You just created an RS232 serial port. Voila.
But as we all know, those old-fashioned serial ports are almost completely gone now. You might still see a serial port on a new motherboard in rare circumstances. But I’ve never seen one on a recent laptop. It’s all USB now.
There is a standard composite device class for USB devices to implement a serial port, and there are several chips available which will implement it for you. But my favourite is a relatively new part, the Microchip MCP2200. Why? Because it’s really easy to use, it works quite well, and it’s cheap. I like cheap.
MCP2200 Example Schematic
Take a look at this simple example schematic (click on it to make it bigger):
You really don’t need much. Aside from the chip itself, you need an R-C circuit for reset, a decoupling capacitor or two, and a cheap ceramic resonator (because why use an expensive crystal when a cheap resonator is good enough?). Oh, and the USB connector of course. That’s it.
Most of those parts should be very self-explanatory. The only question is: which resonator? I use the Murata CSTCE12M0G55-R0 which costs less than 30 cents when you buy a bunch, and less than 50 cents if you buy only one (those are digikey prices). Obviously not an expensive part. This is a 0.5% frequency tolerance resonator. In theory to fully meet the USB specification a 0.25% tolerance part is required, but in practice it’s not – I’ve never had a problem. And heck, it’s only a serial port.
You’ll notice there are a bunch of unconnected pins on the chip. If you read the datasheet you’ll discover the MCP2200 can do a bunch of other things too. But for our simple serial-to-USB task, that’s all we require. Easy.
Size and Price
Aside from its ease of use, there are a couple of other things I like about the part.
One is its packaging. It comes in three different packages, but two of them, the SOIC and the SSOP are pretty easy to solder, so those are the ones I choose. I can solder those parts by hand with a fine-tipped soldering iron and a bottle of flux.
The other thing is of course the price. If we go back to digikey, we discover the chip costs just over $2 if you only buy one, and around $1.50 if you buy a handful. Add in the cost of the resonator and you’re looking at a little over $2.50 for the solution, at a quantity of one. That’s cheap.
The part works on Windows, Linux and Mac, and the Microchip MCP2200 page has a zip file for driver downloads. On WinXP there’s little to do. In that zip file is a Windows INF file. When you plug your MCP2200 board into your PC’s USB port, Windows will automatically detect it, and ask in its usual way about installing software. Simply direct it to that INF file and it’ll be happy. You’ll have to do it several times because the MCP2200 is a composite device, so it identifies itself to the PC as several different devices, and the PC wants to read that same INF file for each one.
Here’s an important note. Basically, you MUST have Service Pack 3 installed if you’re on WinXP. SP2 and older has bugs in its USB handling software. You can try to install the various hotfixes that are mentioned in the Microchip zip file. Or you can just fix everything in one swoop by installing SP3. By the way, installing SP3 can take a while (it took a couple of hours on my PC) so only do it when you can walk away from the computer for a while.
Once you’ve done the INF thing, the MCP2200 appears as another comm port on your PC. In hyperterminal or teraterm it often seems to show up as Com9 for me. Easy.
There are alternatives to the MCP2200. A popular one is the FTDI FT232; it’s been around for a while. Checking digikey, we see the one-off price is around $4.50 for the part. That’s almost double what the MCP2200 costs.
Another is the Silicon Laboratories CP2102. This is a popular chip that’s used in a lot of those USB to RS232 converters you can buy cheaply around the place. The difficulty with this chip is soldering it by hand – it comes in a very small package. Its pricing is decent though – $3 at digikey for one. There’s also the Exar XR21V1410, which is also in a tiny package. And no doubt many other manufacturers have similar parts too. It’s a competitive market.
Many microcontrollers can directly support USB. The Atmel AVR family has the excellent free LUFA project, which by all accounts works very well. This allows you to directly implement USB, including the same type of simple USB serial port, on many AVR processors. Other microcontrollers such as the Microchip PIC family, the TI MSP430 family, etc, have similar solutions. The downside of all these software solutions is that the USB code can consume a fair amount of space (RAM, Flash, CPU cycles) in the microcontroller, so you need to size your micro accordingly to accommodate both your application code and the USB stack code. However for simple applications, something like this can often be a great way to go.
The simplicity and low cost of the MCP2200 make it a great alternative however. If you don’t mind adding the chip to your PCB, it makes for a cheap and easy way to add USB connectivity to any design. I’m enjoying it.