When developing, debugging and testing embedded projects it can be really handy to have a serial port that you can use to print diagnostic messages or data dumps, or use to create a simple command line interface to your firmware. This is something I include in almost all of my microcontroller (MCU)-based projects unless there is a really good reason why not. Most MCUs have a spare UART you can use for this purpose, and you only need two pins, so it is a no-brainer, especially at the prototype stage.
Of course, the MCU produces only logic-level asynchronous TX and RX signals, so some kind of interface is necessary to get them to work with your terminal software. In the olden days we would use a level translator to provide RS232-level signals and connect to the device running our terminal emulation software via a DB-9 serial cable. Getting a reliable connection was always a bit of a rigmarole involving null modem cables, RS232 break-out boxes and sometimes soldering jumpers between DSR & DTR and RTS & CTS pins.
Thankfully, that is no longer because today USB is the only way to go. Many manufactures make USB-UART interface chips that seamlessly convert logic level serial signals to USB. Most use the USB Communications Device Class (CDC) which appears as a virtual COM port on the host. It is then simply a matter of configuring your terminal emulator to use this COM port, setting the communications parameters and you are away.
For no particular reason I have used the Microchip MCP2200 in this role in quite a number of my projects and it works well. Figure 1 shows the block diagram of this device extracted from its datasheet. In addition to the USB serial capability, this chip provides 256 bytes of user EEPROM and general purpose I/O.
You can connect this type of chip directly to your MCU’s TX and RX pins and that will certainly work fine. However, there are a few reasons why you might want to consider isolating the diagnostic port. An obvious one is if your circuit in not ground-referenced or there is any possibility that high voltages may find their way onto the logic power supply under fault conditions. It is heartbreaking enough to blow up your circuit, but much worse if you blow up your laptop or PC at the same time. A more subtle reason for isolation includes the avoidance of ground loops or limiting the conduction of noise from your computer’s power supply into your circuit—especially if you are dealing with precision measurements.
So, how do we isolate the USB-UART interface? The answer is to use one of the low-cost digital isolators such as the Silicon Labs Si8422. This neat chip provides up to 2.5kV isolation and one digital channel each way capable of 150Mbps, all for about $1.50 (US) in unit quantity. Other configurations and packages are available, including larger packages with 5kV isolation. These chips work by capacitively coupling a modulated digital signal across the isolation barrier as shown in Figure 2. A demodulator on the other side restores the signal.
Figure 3 shows the complete circuit as implemented in a recent project of mine. The isolated side is powered from the USB bus via a 3.3V regulator. The TX and RX led indicators are optional. The two 33 Ω resistors provide a degree of protection on the D+ and D- pins.
In researching this article, I came across another USB-UART bridge from the same vendor as the isolator. This one, the CP2120, looks very interesting as it does not require an external crystal and incorporates a voltage regulator on-board. I have not tried this, but it looks like it could considerably reduce the parts count and (already low) cost. It is definitely on my list for next time.
As a final note, you need to be careful leaving an exposed serial port on your device when it gets out in the wild as it presents a serious security vulnerability. You might want to make sure it is disabled in your production code.
“Digital Isolators – Silicon Labs.” Accessed November 27, 2020.
“MCP2200 – USB – USB Bridge.” Accessed November 27, 2020.
“USBXpress USB Connectivity Bridges – Silicon Labs.” Accessed November 27, 2020.