27 May 2023 - tsp
Last update 09 Jan 2024
22 mins
This blog entry is just a summary of the most basic configurations of the CP2102N USB to TTL chip as well as a description of a playground board design that exposes all pins of the CP2102N to the outside for evaluation purposes and in addition provides functionality of a half duplex RS485 bridge. The CP2102N is one of the most robust and simple to use (especially also on the software side) chip that I encountered up until now - and it provides all features one would require for simple devices. It’s a very versatile device that can be customized so the described usage only represents a small subset of what’s possible. The CP2102N supports USB 2.0 full-speed which is sufficient for microcontroller applications under most circumstances. The device requires no external clocking, supports data transfer at up to 3 MBaud, requires only small operating current and can be run either bus powered or device powered depending on the application. In addition the CP2102N also supports chargers with information about available bus current and presence to implement battery charging in a simple way.
In addition the manufacturer provides a customization tool that allows one to change the VID/PID instead of
using the default one (the biggest drawback is then that you need to provide your own mappings in the devd
or devfs
configuration or even need to write your own signed device drivers on some more obscure operating
systems (like MS Windows)). In addition to standard UART operation the device also supports triggering an external
half duplex RS485 driver like the MAX485 by just setting a single bit so one can build a two component low cost
RS485 interface using the CP2102. Contrary to other cheap solutions each device has a unique serial number that
can also be customized using the manufacturer supplied tool which allows one to distinguish the devices when
assigning device links. On top of all that the device - when using a custom driver - offers 7 freely usable
GPIO pins; in the usual configuration they are used to drive TX/RD LEDs, the RS485 TX/RD switch and support the
transmission of a wake up signal to a suspended host via. The other 3 GPIOs are unassigned by default. Note
that the default configuration also does not enable the LEDs as well as the RS485 feature. You have to enable
those via the configuration utility!
In contrast to some chips like the famous FTDI USB to serial adapters the CP2102 are easier to use - also from
the software side since they are delivered as standard communication class device so there is no additional
driver installation required. One can still distinguish the devices (and assign them specific alias in the devd.conf
by identifying them by serial number which is unique for the CP2102).
The first thing to consider when using the CP2102 is the way the device is powered. There are three main paths one can take:
VDD
(with a decoupling network) for the application circuit.VBUS
. REGIN
and VDD
have to be attached
to the application circuits 3.3V rail.
REGIN
pin.In any case the reset pin has to be pulled up with a $1k\Omega$ resistor to VDD
. It’s also good practice
to connect the bus voltage to VBUS
via a voltage divider. Since VBUS
is used only to detect presence
of an USB host this still works but clamps the voltage seen by the CP2102 to stay within allowed absolute maximum
limits even when the device itself is not powered by the application circuit. This is of course not required
but not a problem anyways when powering the application directly from the LDO of the CP2102.
Often not mentioned one should add a proper TVS diode to each of the bus lines. A quad array like the TPD4E02B04DQA
might be a good idea. One usually forgets those but this provides additional protection against voltage surges
and static electricity. I’ve personally already lost 3 CP2021N by high voltage spikes in a lab when arcing occurred
on another power line. Adding TVS diodes prevented any further faults. They don’t cost much and may safe your
whole device. Use them.
All power lines (REGIN
and VDD
) have to be properly decoupled. For REGIN
this could be
a $1 \mu F$ and $100 nF$ capacitor, for VDD
a $4.7 \mu F$ and $100 nF$ capacitor in parallel. One has
to adjust this to ones own needs of course.
That’s already the most basic way of using the CP2102:
In this circuit the GPIO pins 0 and 1 have also been attached to LEDs that indicate transmission and reception of data. This might be nice especially in an experimental environment - but is entirely optional of course. One can also reconfigure the GPIOs for other purposes or just leave them unconnected.
The two solder jumpers allow to select how the device should be powered.
JP1 1-2 | JP1 2-3 | JP2 | Power mode | CP2102 bus powered | Application bus powered |
---|---|---|---|---|---|
Open | Open | Open | Won’t work, device and regulator not powered | ||
Open | Open | Closed | Won’t work, not specified since the regulator input is floating | ||
Open | Closed | Open | Won’t work, regulator input and VDD don’t get power from anywhere | ||
Open | Closed | Closed | The device is powered by the application circuit at 3.3V, bus power is not used | N | N |
Closed | Open | Open | The device is bus powered, the application is not powered by the bus | Y | N |
Closed | Open | Closed | The device is bus powered, the application draws its supply from the 3.3V LDO of the CP2102 (bus powered) | Y | Y |
Closed | Closed | Open | Won’t work, bad idea | ||
Closed | Closed | Closed | Won’t work, bad idea |
The CP2102 offers another nice feature. The pins CHREN
, CHR0
and CHR1
are especially interesting
when one wants to charge batteries via an external charge controller. After the CP2102N performed negotiation
on the USB bus they signal if and how much current a charger may draw.
CHREN
goes high one may draw at most 100 mA from the busCHR0
signals capability of drawing up to 500 mACHR1
goes high one can draw up to 1.5AAs the most simple example lets take a look at a very simple USB to TTL and USB to half duplex RS485 board. Of course boards just offering USB to TTL serial conversion can be bought very cheap on common merchant platforms - but it’s a good learning exercise and supporting RS485 is less common on such boards. This board has been designed around the CP2102N as well as the MAX485E - contrary to the small boards sold on most platforms all I/O pins of the CP2102N have been exposed via a pin header so the board is rather bulky. This has been done to provide a playground for GPIOs, provide access to the flow control pins and allow access to the charge control pins during evaluation of the chips. It’s more of a playground than a practical implementation. The only assumptions that have been made are:
All design files are provided in a GitHub repository. The schematic design is pretty simple:
J1
). On the board a USB 2.0 B
socket has been used since it’s compatible with most existing USB installations
and cabling out in the world as of today. Of course one could consider an USB 3.0 B
connector for new designs though the speeds utilized by the CP2102N do not reach
anywhere in the USB 3.0 regions.TPD4E02B04DQA
has been used though this has been designed for USB-C devices. As one can see only
three of the diodes are in use, the forth is just tied to ground. This is also
the hardest part to solder due to the very small package size.REGIN
as for a bus powered device. Two
decoupling capacitors ($1 \mu F$ and $100 nF$ are provided as close to the chip
as possible).VBUS
. As mentioned above this is not required for a bus powered
device but keeps the device in absolute supported margins when providing power
via the application circuit. Even though this is not possible on this board adding
those resistors does not hurt (when one’s not designing in industry scale
where every small saving in material cost helps).JP1
and JP2
allow one to select between RS485 and
TTL operation.
JP3
to add a $120 \Omega$
termination resistor between A and B line.The following table contains a list of all components I’ve personally used to build such boards. Most of them (like resistors, capacitors and terminals) are freely interchangeable. Capacitors are all metal film capacitors, resistors thick film resistors - for them there had been no particular reason to choose them except for a roll of them having already been kept on stock.
Identifier | Mouser Nr. | Manufacturer number | Component Description |
---|---|---|---|
U1 | 595-TPD4E02B04DQAR | TPD4E02B04DQAR | ESD suppressor / TVS diode array |
U3 | 700-MAX485ECSA | MAX485ECSA+ | MAX485E RS485 interface (half duplex) |
U2 | 634-CP2102NA02GQFN28 | CP2102N-A02-GQFN28 | CP2102N USB interface |
R1, R6 | 603-AC0805FR-0724KL | AC0805FR-0724KL | $24 k\Omega$ resistor, 0805 package (any type will do) |
R2, R7 | 603-AC0805FR-1047KL | AC0805FR-1047KL | $47 k\Omega$ resistor, 0805 package (any type will do) |
R4, R5, R8 | 603-AC0805FR-07120RL | AC0805FR-07120RL | $100 \Omega$ resistor in schematic, used $120 \Omega$ due to them being on local stock; R8 has to be $120 \Omega$ (any type is ok) |
C1, C3, C5 | 581-08055C105K4T4A | 08055C105K4T4A | $1 \mu F$ capacitor, 0805 package (any type will do) |
C2, C4, C6 | 581-08055C104K | 08055C104KAT2A | $100 nF$ capacitor, 0805 package (any type will do) |
D1, D2 | 593-LSM0805412V | LSM0805412V | Standard 0805 packaged LED. Any generic LED is usable. |
J1 | 710-61400416121 | 61400416121 | USB B connector by Wurth |
J2 | 2.54mm pitch 2x8 pin pin header | ||
J3, J4 | 2.54mm pitch 4 pin screw terminal | ||
JP1, JP2 | 2.54mm pitch 3 pin pin header | ||
JP3 | 2.54mm pitch 2 pin pin header |
The board layout is also rather simple.
TPD4E02B04DQA
TVS diode array is the most challenging part to solder
on this board. The array is provided in a USON-10 DQA
package. This has
$500 \mu m$ pitch of pads hidden below the package of the device. Reflow soldering
this part is very simple. Soldering in any other way very tricky, nearly impossible
as well as error prone and time consuming. Of course the TVS diodes are optional
and can be left out - but one will loose ESD protection in this case.As for any more complex board routing directions for top and bottom layer have been chosen to be (nearly) orthogonal (horizontal routing on the back side, vertical routing on the top side). Again the design goal was not the most compact board but a working and simple to assembly playground.
The PCB has then been ordered at PCBWay. Note that this board does usually not qualify for the cheapest option since the package of the TVS diode array is not possible with $6/6 mil$ option. When leaving out the TVS array the board is simple and cheap though. Just use default options, choose a color for your silkscreen and upload the ZIP file provided in the GitHub repository or ZIP up all exported Gerber files from KiCad (make sure to follow the guidelines provided by PCBWay). PCBWay manufactures your PCBs in around 24 hours and ships them very fast.
As usual for this manufacturer PCBs arrived pretty fast:
The PCBs have then been first reflow soldered with a heat gun - first the capacitors and resistors, then the TVS diode array, the CP2102N and then the MAX485E. The last element that has been added on the surface had been the LED. After that the THT components have been added (first the screw clamps, then the pin headers and jumpers and in the end the bulky USB connector).
At the end the PCBs have been cleaned in an ultrasonic Isopropyl alcohol bath for 10-15 minutes to remove any residues of the reflow soldering paste. This is usually a good idea for electronics devices (as long as they’re not damaged by ultrasonic sound like quartz resonators and some plastic parts for example)
As the absolute first test the PCB has been attached to the USB port and the dmesg
output has been observed. Then one should see the attachment of an CP2102N
device
in the kernel log.
One can then directly use any terminal application or software to transmit and receive data with arbitrary Baud rates via the TTL port when jumpering correctly. Neither the LEDs nor the RS485 port will work (the latter one at least not bidirectionally - the MAX485E will permanently drive the A/B line pair) at this point in time. This is caused by missing configuration of the chip. To test the receive part one can simply connect the center pin of both mode selection jumpers. This will echo any written data back into the device.
To configure the chip one requires Simplicity Studio by
Silicon Labs. The old standalone configurator doesn’t work for the N series of the CP2102.
You have to register for an account and download a pretty huge archive. After that
one has to log in into the application. The easiest way to download the correct
SDK is by attaching a device and letting the application figure out which components
to download. Then one can launch the new Xpress Configurator
from the menu.
The first thing to configure are the basic device configurations:
One can assign any product and vendor ID - keep in mind that then you have to
provide your own devd
or devfs
configuration or even own device
driver (for MS Windows using masochists). One can also freely choose the manufacturer
string and the serial as well as the announced required bus power. One might be
tempted to write a custom serial - the easiest way to guarantee a unique serial
is using the internal serial number though. In this case the serial exposed will
be calculated from a unique 128 bit number unique to the given chip. For this
board one should also announce that it’s bus powered and configure a proper maximum
power usage which depends on the application circuit upstream. When using more
power one should also use the charge control pins to trigger power supply to the
application circuit.
The next configuration group are the port settings for all I/O ports of the CP2102N.:
Here one can decide on the modes as well as latching of the I/O pins. Usually defaults are what one needs when one doesn’t know better for a simple USB to TTL conversion board. The GPIO configuration though will require some tweaking to enable RX and TX LEDs as well as the driving of the RS485 half duplex transmission enable pin on the MAX485E:
The last configuration option configures the virtual serial port. Here one can configure the maximum allowed Baud rate, a set of supported Baud rates (when selecting User Programmable any Baud rate up to the maximum rate can be used independent of other selections)
Keep in mind that RS485 mode switching is only supported for Baud rates larger or equal to 300 bps so it’s a good idea to limit the supported Baud rates to default ones larger or equal to 300 bps. The supported set of data, stop and parity bits depends on the particular application. Application software is only capable of setting modes that are enabled on the device.
Now one can simply select Program To Device
- that’s it for small series
of devices. When building a larger number of devices one can use the SDK provided
by Silicon Labs to write automatic configuration scripts that can program devices
while being transferred through the production line.
The last initial test carried out on the device has been RS485 mode. Simply jumper the jumpers accordingly and start the data transfer. One will see that during transmission the device always enables the RS485 line driver. After all data has been transmitted the driver goes low again.
Note that all links in this section are Amazon affiliate links. This pages author profits from qualified purchases
Which tools have been used in construction of this board? Since the board contains reflow solder parts it has been convenient to use:
This article is tagged: Tutorial, Basics, Electronics, DIY, RS485
Dipl.-Ing. Thomas Spielauer, Wien (webcomplains389t48957@tspi.at)
This webpage is also available via TOR at http://rh6v563nt2dnxd5h2vhhqkudmyvjaevgiv77c62xflas52d5omtkxuid.onion/