There are a number of widely used methods to connect microcontroller projects to USB, all of which are not entirely satisfactory:
- The commonly used FTDI chips are somewhat expensive, and their manufacturer has made some unpopular decisions with their driver support (although technically, the FTDI drivers work quite well).
- Atmel also offers microcontrollers with built in USB, but those also tend to be a bit expensive.
- Software USB stacks use a considerable proportion of the microcontroller’s processing power, and as not always as reliable as hardware solutions.
When I therefore heard about a very cheap (40 cents a piece) USB to serial converter IC, the WinChipHead CH340G, I was eager to try it, and bought a few (I bought mine on AliExpress, but they are now also available at Boxtec). A prototype I built on a breadboard worked reasonably well, so I decided to try my hand at a custom PCB design:
To a large part, this follows a reference design from the vendor datasheet, using an Eagle part made by blogger [Ian]. I added a few customizations:
- Boxtec’s Christoph Schneeberger successfully convinced me to include a fuse. Though one might suspect a nefarious plot to sell more fuses, he’d probably make a bigger profit selling replacement parts for melted down unprotected boards (not to speak of potentially frying the USB port of a laptop).
- I added LEDs on the RX and TX lines. Since serial lines are high when quiescent, I made them active low.
- I put an ICSP header on the board so it could easily also be used as a bitbang programmer.
In many ways, the resulting design was a bit more complex than what I had done before: It’s my first design involving an USB connector, and it uses more SMD parts (12) than any of my previous designs. I was therefore quite pleased when I managed to assemble my first copy of it with relatively little drama, and the functionality worked as designed (As usual, my application of solder paste for the CH340 was somewhat uneven, so I had to fix some shorts and one flaky pin connection). The serial connection seems to work even at high rates, and the bitbang programming works at the stately pace of about 1.2KB per minute.
Read more: Introducing ChipHeadBang