Sunday, April 19, 2015

Introducing ChipHeadBang

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.

I should mention that the CH340 has its drawbacks: Documentation is hard to find, especially if you don't speak Chinese. Driver support is iffy: My understanding is that the Linux and BSD drivers are OK, but the Windows and Mac drivers are not properly signed, and the Mac drivers will actually cause kernel panics on the latest versions of OS X. I was quite satisfied with quality of the commercial third party OS X driver I ended up buying, and the price is very reasonable, but if building a cheap solution was the objective in the first place, even that reasonable price does of course spoil the economics (if not the hedonics) of the exercise.

UPDATE: Thanks to the codebender team, there is now a working free Mac driver for CH340 again, even a properly signed one.

Design files available on Github: https://github.com/microtherion/ChipHeadBang

3 comments:

  1. You could just hack a 1EUR USB dongle with this chip, and solder some wires on the chip itself to use those pins. No need to make a full board.

    ReplyDelete
    Replies
    1. From a technical point of view, you are undoubtedly correct (although at least I would find this kind of dead bug wiring rather challenging, especially if this is supposed to stay mechanically reliable over the longer term), but I would argue that this somewhat misses the point: I'm engaging in most of my projects not so much in search of a solution, but in search of a challenge, and to entertain myself.

      Delete
  2. And on the software side, do you use a special config of avrdude? I am trying to figure out if the DCD/RTS/CTS pins could not be used as GPIOs.

    ReplyDelete