Fork me on GitHub

Project Notes

#406 Custom CH340G USB to UART interface

Build a USB to TTL serial interface on a breadboard using the CH340G interface chip, and use it to program Arduino sketches on an ATmega328P.

Build

Notes

The CH340G is a USB to UART Interface chip. It is often used as a cheap alternative to more established brands and products such as the FTDI FT232RL. The CH340G is commonly found in:

  • Arduino Nano clones
  • USB to Serial adapters

In this project, I’d like to see how easy it is to build a USB to Serial interface on a breadboard. To test it out, I’ll use it program Arduino sketches on an ATmega328P.

CH340G Key Specs

CH340 is produced by WCH 江苏沁恒股份有限公司 (Jiangsu Yuheng Co., Ltd.). It is a series of USB adapters - with variants providing serial, parallel or IrDA interfaces. The CH340G supports serial with common flow control signals.

Key features:

  • USB 2.0
  • Supports common flow control signals RTS, DTR, DCD, RI, DSR and CTS.
  • Supports RS232, RS422 and RS485 with external level shifting components.
  • Baud rate range from 50bps to 2Mbps.
  • 5V and 3.3V operation.

Pinout:

Pin Name Description
1 GND Ground. Connect to the ground pin of USB bus
2 TXD UART Data Transmit output
3 RXD UART Data Receive input
4 V3 Internal 3.3V reference for USB physical layer
5 UD+ USB D+ signal
6 UD- USB D- signal
7 XI Crystal oscillator input
8 XO Crystal oscillator output
9 CTS# UART flow control: Clear to Send
10 DSR# UART flow control: Data Set Ready
11 RI# UART flow control: Ring In
12 DCD# UART flow control: Data Carrier Detect
13 DTR# UART flow control: Data Terminal Ready
14 RTS# UART flow control: Request to Send
15 R232 Auxiliary RS232 enable. Active high, internal pull down
16 VCC Supply rail for the chip

Notes:

  • V3: Decouple with a 4.7-20nF capacitor when in 5V operation, or tie to VCC when in 3.3V operation.

Drivers and Setup for MacOSX

CH340G Drivers

If the CH340G serial chip is not recognised my MacOSX, a driver is required. See:

I’ve “cached” copies of the drivers I’ve used in the past in the drivers folder:

  • CH341SER_MAC.ZIP
  • CH34x_Install_V1.3.zip - latest version I’ve used

Chips and DIPs

I have some CH340G chips in SOP-16 package (from a seller on aliexpress). I’ve mounted one on a DIP adapter, and found a micro-USB breakout:

ch340g_chips_and_dips

Examining a Commercial CH340 USB-Serial Adapter

I have a CH340G USB adapter that I got along with an Arduino mini, so I took a closer look to see if it usde the CH340G chip in any unexpected ways.

Tracing the circuit, it turns out to be very straight-forward. A few things to note:

  • the 3.3V/5V selector actually just enables/disables a 662K 3.3V regulator to supply the outbound pwer rail. It does not switch the operating voltage of the CH340G itself (or the data levels)
  • includes a power indicator LED, and a transmit indicator LED
  • has 1kΩ resistors inline the RX/TX lines; not particularly sure why (not mentioned in the CH340G data sheet)
  • lots of ceramic bypass capacitors. I’m not sure of the actual capacitance values.

ch340g_adapter

ch340g_adapter_schematic

Building the CH340G Interface on a Breadboard

On one breadboard, I have a basic 5V CH340G setup:

  • RX and TX LEDs; Power LED
  • DTR, TXD and RXD connected on the serial side

On another breadboard, I have an ATmega328 (with Arduino bootloader) wired up for programming. See LEAP#405 ATmegaSerialProgrammer for more on programming over serial.

Breadboard

Schematic

Build

Here’s a quick demo (uploading a sketch). I’m programming the ATmega328 with the UsbUartCH340G.ino sketch - a simple blink variant that also sends bursts of serial output (to exercise the RX LED).

clip

A Protoboard CH340G Demonstration

A final prototype before doing anything more serious - I’ve switched to SMD components and built up for testing on some protoboard with DIP adapters. A few changes to the design:

  • added a 500mA resetable polyfuse on the USB supply
  • connected both DTR and CTS lines to the 6-pin device adapter
  • bumped up the LED current-limiting resistors to 2.7kΩ

The device pinput sequence I’ve selected is as follows. This suits some devices, but may need wires crossed for others.

Pin Name Note
1 DTR  
2 RXD Connects to TX on the device
3 TXD Connects to RX on the device
4 VCC  
5 CTS  
6 GND  

CH340GProtoboard_bb

CH340GProtoboard_schematic

Here’s a sketch of the layout I used:

CH340GProtoboard_layout

Credits and References

About LEAP#406 USBSerialCH340

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

Project Source on GitHub Return to the LEAP Catalog
About LEAP

LEAP is my personal collection of electronics projects - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know or send a pull-request.

NOTE: For a while I included various scale modelling projects here too, but I've now split them off into a new repository: check out LittleModelArt if you are looking for these projects.

Project Gallery view the projects as an image gallery Notebook reference materials and other notes Follow the Blog follow projects and notes as they are published in your favourite feed reader