Thursday, February 1, 2018

How to build your own USB to UART serial converter using FT232 with voltage level shifting

The board includes 500mA fuse protection, EMI filtering, power LED indicator, RX and TX LED indicators, and a voltage level shifter that makes it compatible with 3.3V and 5V boards. This way you don't need to check the jumper if it outputs 5 or 3.3V so you don't risk burning your microcontroller. It works with both voltages.

Update: 2024, March, 6: I made another serial adapter build around FT231 which require less components since it is 5V tolerant and is also cheaper. It is part of a development board:

USB to UART serial converter board tutorial DIY home build

Parts needed:

1 x USB Type B connector
1 x MC33190 - PPTC Resettable Fuse = 0.2$ (Farnell order code: 1800750)
2 x BLM21PG221SN1D - Ferrite Bead = 0.14$ (Farnell order code: 1515661)
2 x Green LEDs
1 x Red LED
2 x TVS Varistor 0603 = 0.44$ (Farnell order code: 1838966)
1 x 10 µF 0805 capacitor
1 x 0.1 µF 0805 capacitor
2 x 1 µF 0805 capacitor
3 x 220 ohm 0805 resistors
1 x 10k 0805 resistor
2 x 1k 0805 resistors
1 x 3.3V Zener Diode
1 x 1N4148WS - Small Signal Diode
1 x 1x6 Receptacle
1 x FT232 IC = 1.9$ on eBay
1 x 70x34 mm double side copper clad board

USB to UART serial converter with voltage translator schematic

FT232RL USB to UART converter with voltage level shifter translator
Click to enlarge or right click and open in new tab

Starting from left we have a USB type B connector. In series with the USB 5V VCC is MC33190 a PTC (Positive Thermal Coefficient) resettable fuse F1. This protects the USB host by limiting the current to 500mA.

After the fuse, there is L2 BLM21PG221SN1D ferrite bead that stops high-frequency switching noise from the IC to be induced on the USB power supply.

D1 and R1 is a green power indicator LED and it's current limiting resistor.

C1 and C2 are decoupling capacitors - they act as a current reservoir for the chip during peak current draw. The 10uF capacitor filters lower frequency whereas the 0.1uF filters higher frequency noise to ground.

VR1 and VR2 are CG0603MLC-05E varistors used to protect the IC from ESD spikes. Notice that the USB shield is connected to ground through the L1 ferrite bead. This ensures that any ESD voltage spike will be absorbed by the inductor and will not affect the ground potential.

D4 is a red LED that indicates UART transmission and D5 is a green LED that indicates reception.

The pin 13 of the FT232RL is the 3.3V out from the internal voltage regulator and is tied to the VCCIO pin 4. This puts the IC in 3.3V mode meaning it will output 3.3V on the transmission line. The reason for this is that I wanted to make it compatible with 3.3V and 5V boards.

In series with the TX (transmission) line is R3 and in parallel is D2 a 3.3V zener diode. If the FT232 communicates with a 5V board the 3.3V on the TX will be read as HIGH by the 5V board. The D2 zener is there to protect the FT232 chip in case that more than 3.3V will be on the line for some reason. This shouldn't happen because the microcontroller should have the receive pin in high impedance mode but the user could set this pin as HIGH.

R2 is a 10k pull-up resistor that keeps RX line at 3.3V. D3 in series with RX line is a signal diode that blocks voltages from the other side in case there is more than 3.3V. Let's say that the chip communicates with a 5V MCU. When the MCU puts 5V on the RX line, the voltage will be blocked by the diode D3 and the R2 will keep the RX pin at 3.3V. But when the MCU puts a LOW voltage on RX line, the RX pin of the FT232 will be pulled to ground.

At the right side of the board is a 1 row, 6 pins receptacle (female header). C3 and C4 are 1uF bulk capacitors for 5V and 3.3V output.

Output pins:

1 - 3.3V (max 50mA)

2 - 5V (USB VCC, max 500mA)

3 - TXD (connect to RX)

4 - RXD (connect to TX)

5 - DTR

6 - GND

The DTR pin must be connected to the Reset pin of the microcontroller through a 100n capacitor. Normally the DTR is high and before programming it will be pulled low for a very short time by the IC in order to reset the microcontroller and activate the bootloader.

Note that the 3.3V output from the FT232 internal voltage regulator can only supply 50mA. Make sure your device will not exceed that.

Update 1:

When the microcontroller is powered from 5V, the DTR pin low state goes to only about 1.7V instead of ground which is not enough to reliably reset the microcontroller. Since the voltage is at the threshold, sometimes the programming will work and sometimes not. More details below. To fix this issue, the DTR signal must be level shifted using a simple mosfet.

How is the DTR pin used to program the microcontroller

DTR stands for Data Terminal Ready and is one of the control signal that belongs to RS-232 serial communication. In the context of programming a microcontroller we use this pin to reset the microcontroller (MCU). When you upload the code to the microcontroller, the host PC will pull this pin low, but having a MCU in a reset state is of no use. So to convert the low state to a low short pulse, we place a non-polarized capacitor in series with the DTR signal (see the below schematic). This low pulse will reset the microcontroller and if a bootloader is present, it will be loaded. Then the bootloader will take the code received from the PC and write it on the microcontroller.

DTR reset issue

In order to support both 3.3V and 5V microcontrollers, the FTDI is configured to output only 3.3V on I/O pins. When the microcontroller is powered from 3.3V there is no issue but when it uses 5V then the DTR which is at 3.3V will not be able to trigger the reset every time. This is an intermittent issue. The problem has to do with how the capacitors work. Initially one capacitor plate is charged at 5V through the pull-up reset resistor and the other side is charged at 3.3V by the DTR pin. When the DTR is pulled low, the reset side will not be at 0 volts but 1.7V instead (5 - 3.3 = 1.7V). This voltage is not low enough to have a reliable reset nor high enough to prevent the reset all the time. The reset will occur or not depending of electrical noise. For example if I was putting my finger on the reset line while programming or connect a logic analyzer, the reset would work.

When the DTR signal goes high again, the voltage on the reset node will spike to 5 + 3.3 = 8.3V but this from what I understand is not a concern since the Reset pin is the only pin able to withstand 12V without damage. However a diode can be used in parallel with the pull-up reset resistor.

Simple and cheap bi-directional voltage level shifter

To solve the DTR reset issue, a simple voltage level shifter can be implemented by using an N-channel mosfet and a pair of 10k pull-up resistors.

DTR voltage level shifting

The DTR pin is connected to the source of the mosfet. Let's call this LV (low voltage) side. The mosfet drain is the DTR after has been voltage level shifted. Let's call this node HV (high voltage). When the DTR is driven low, the mosfet turns on pulling the HV low. When HV is driven low, LV is also driven low through the mosfet’s body diode, at which point the mosfet turns on. In all other cases, both LV and HV are pulled high to their respective logic supply voltages. The pull-up resistor (R1) on LV side is added to speed up the rise time. The resistor (R2) on the HV side required to pull-up the DTR to the voltage that the microcontroller runs at.

The N-channel mosfet can be of any type provided that the voltage gate threshold is below 3.3V. Recommended products are: NX7002AK, 2N7002PW.

USB to UART converter pinout

USB to UART converter board logo
The logo didn't stick well

If you want to know how I made the PCB, visit Double sided PCB tutorial.

Here is a tutorial on how to use this serial adapter with Atmel Studio.

Download schematic and PCB layout projects

Eagle - USB to UART using FT232RL (Revision 1)

No comments:

Post a Comment