Frank's Random Wanderings

USB to Serial – Fast and Easy

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):

MCP2200 schematic

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.

Software

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.

Alternative Parts

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.

9 thoughts on “USB to Serial – Fast and Easy

  1. china cat

    hi.frank:
    thank u write the page, i found that use mega128 can not convert true negative differrntial , But their FAE do not willing tell me the true images!

  2. frank Post author

    I’ve no idea of the different ways to program a PIC. I very rarely use them, and when I did I used a programmer from Microchip. Asking your question on a Microchip forum might be a better idea. I would point out that if the sole reason for having the part is to program the PIC, for cost reasons you might consider leaving it off the board. Just have a programming header on the board (or even better, an unpopulated header and use pogo-pins or similar to connect to the pads, or make an edge connector on the PCB) and have your production programmer on a separate board. Good luck with your project.

  3. mjlynch712

    Absolutely excellent article. I’m very new to all of this, but for a project I plan to use a PIC32 as my main processor. Would you advise the MCP2200 for USB to serial or stick with the FTDI?

    All I plan on using the chip for would be to program the PIC32. It’s for a school project and my argument for using the MCP2200 over the FTDI was, if the product went to manufacture, it’s more cost effective to buy all parts from the same manufacturer

    Many thanks

  4. Royce

    The MCP2200 wins with hobbyists or small quantity manufacturers due to its easy to solder packages (SOIC/SSOP).

    It’s something that you can instantly wire ‘on the fly’ .

  5. frank Post author

    Glad you like the website. I presume you mean “DMA” rather than “EMI”. I have also used the FT232. It’s a little bit more expensive (bad), but the thing I personally like about the FT232 is that quite stable drivers are built into Windows, so it’s pretty much just plug it in and it works. Whereas the MCP2200 requires some driver install.

  6. rayher

    hi

    I play circuits with MPS430 and STM32, I like your website 🙂

    If you have some special consideration, such as EMI, FT232R may be a better solution. I made a data logger which transmits engine data to PC via USB COM, only FT232R can sustain the engine EMI attack.

  7. frank

    Minor update: In general, make sure the MCP2200 is powered by the USB power as shown in the schematic, and not by some other circuit. I had one board where the MCP2200 was powered by the board itself, not by the USB power. When power to the board was cycled, either Windows or the MCP2200 didn’t like this, and the virtual COM port stopped working. Modifying the board to power the MCP2200 from the USB 5V solved the problem, and power cycling the board no longer caused any issues.

Leave a Reply

Your email address will not be published. Required fields are marked *