This is only a preview of the June 2024 issue of Silicon Chip. You can view 57 of the 112 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Arduino Clap Light":
Items relevant to "ESR Test Tweezers":
Items relevant to "MicroMag3 Magnetic Sensor":
Items relevant to "USB-C Serial Adaptor":
Items relevant to "DC Supply Protectors":
Items relevant to "WiFi DDS Function Generator, Pt2":
Items relevant to "Arduino bin reminder":
Purchase a printed copy of this issue for $12.50. |
Project by Tim Blythman
USB C
SERIAL ADAPTOR
USB Type-C (USB-C) was introduced around 10 years ago and is now becoming
standard. While USB-serial adaptors with Type-C sockets are available, many do not
adhere to the USB-C standard and may also have Windows driver problems. Our
design, presented here, has no such drawbacks and is relatively simple and compact.
W
e have started adding USB-C sockets to our projects as the necessary components have become available in a format that is easy to solder.
Because almost all new smartphones
and tablets have USB-C sockets, USB-C
chargers and cables are becoming commonplace.
Small electronic modules have been
a great boon for many reasons. In parallel with the rise of Arduino, they
have made it very easy to connect
microcontrollers to other electronic
components.
We have a bit of a love/hate relationship with USB-serial adaptors. While
they are incredibly useful and inexpensive, sometimes the chips used in
them are clones.
You might not have any idea of that
until a Windows update causes the
device to stop working. A clone chip
can look identical to the real deal;
sometimes, the only way to tell is to
X-ray it!
It isn’t just a single chip that suffers from this problem. Chips labelled
FT232, PL2303 and CH340G have
caused problems in the past. Others
may be vulnerable too.
Our design doesn’t have this problem because we use a PIC microcontroller programmed to act as a USB/
serial bridge, and it identifies as a
generic CDC device, so there should be
no way that the drivers can go wrong.
Windows, Linux and macOS recognise
it without needing any special drivers
installed and should work immediately after being plugged in.
We have used USB-serial adaptor
modules based on the CP2102 chip
in several projects. We covered this
module with a dedicated article in
the January 2017 issue (siliconchip.
au/Article/10510). One advantage of
Fig.1: a USB-C source provides pullup currents, while a sink has pulldown
resistors. Both can monitor the voltage on the CC line to determine what has
connected to the other end of the cable. The source applies different currents (Ip)
depending on its capacity to supply current to VBUS, which the sink can detect
as differing voltages on the CC line. Advanced modes, like power delivery (PD)
and dual role (DRP), are negotiated through digital signalling on the CC lines.
68
Silicon Chip
Australia's electronics magazine
the CP2102 is that, like our design, it
doesn’t require drivers to work with
modern operating systems.
Because of that, both the CP2102
module and our version will work
if plugged into our Pico Digital
Video Terminal from the March and
April 2024 issues (siliconchip.au/
Series/413).
The most common CP2102 module
is a compact device with a micro-USB
socket to connect to a computer and
a six-pin header to provide 3.3V logic
level UART (universal asynchronous
receiver transmitter, ie, serial) signals.
So we have patterned our designs on
that one.
USB-C advantages and
challenges
USB-C is becoming ubiquitous; even
Apple products like the iPhone, which
have long had proprietary connectors,
have switched to using USB-C, starting
with the iPhone 15 in 2023.
The latest version of the Microchip
PICkit debugger and programmer, the
PICkit 5, also has a USB-C socket. We
think that is an improvement over the
micro-USB socket on its predecessor,
the PICkit 4. We have reviewed the
PICkit 5 in the November 2023 issue
(siliconchip.au/Article/16016)
Although only slightly larger, in our
experience, USB-C plugs and sockets
are more robust than the micro-USB
and mini-USB parts that preceded
them. USB-C plugs and sockets are
also symmetrical, which means they
are less fussy to use.
USB-C to USB-C cables also exist,
siliconchip.com.au
USB-C Serial Adaptor Features & Specifications
● Drop-in replacement for compact CP2102-based USB-serial
modules with the same connector pinout
● Uses the now standard USB-C socket instead of a micro-B
USB socket
● Uses a low-cost PIC16F1455 microcontroller with a USB full-speed
peripheral
● Moderate component size for hand construction
● Supports 8N1 format and a wide range of baud rates (47 baud to 3Mbaud)
● 3.3V, DTR, RX, TX, GND and 5V connections
● LED indicators for power, data reception and data transmission
● No concerns about Windows drivers refusing to work with it due to
counterfeit blocking attempts
USB-C Serial Adaptor Kits (SC6652, $20)
Includes the PCB, programmed microcontroller and all other parts to build
the module; see the parts list later in this article.
in which case the cable ends are even
interchangeable. They are certainly
less bulky than the USB sockets and
plugs that appeared over 20 years
ago. So it is no surprise that USB-C is
becoming popular.
USB-C is also more complex than
its predecessors and requires some
knowledge to implement correctly.
That has tripped up some engineers
who don’t understand the requirements fully.
Even the Raspberry Pi Foundation
had trouble with this, as their first
release of the Raspberry Pi 4 had a
hardware bug that meant it would not
work with some USB-C cables, specifically ‘smart’ e-marked (with embedded electronics) cables. Older, simpler
legacy cables appeared to be immune.
In simple terms, the signalling resistors used to determine the orientation
and role of the cable (in combination
with the CC wire in the cable) were not
connected correctly. This meant that
very early versions of the Raspberry
Pi 4 boards were identified as audio
adaptors instead of devices requesting a 5V power source and thus did
not work.
Legacy cables, such as USB-A to
USB-C types, lack the CC wire in the
cable and thus do not respond to the
incorrect signalling and deliver power
regardless. Fig.1 shows how the signalling should work. There is more
background on this at siliconchip.au/
link/abu0
We’ve seen some versions of the
CP2102 USB-serial modules that have
replaced the micro-USB socket with
siliconchip.com.au
a USB-C socket but they completely
omitted the signalling resistors. That
means that these modules will not
work in all cases.
Such devices may appear to have
intermittent faults, working with some
cables or hosts but not others. At worst,
they might not work at all.
Our USB-C Serial Adaptor
So, this USB-C Serial Adaptor is a
drop-in substitute for the cheap but
functional CP2102 USB-serial Module
and it actually works reliably!
Our Adaptor is a small PCB with
a USB-C socket at one end and a sixway header at the other. Unlike the
prebuilt modules you can buy, this
is a constructional project you must
assemble yourself. We have used some
small parts, but it should be eminently
doable for those with much experience
in SMD soldering.
It uses a PIC16F1455 microcontroller for its USB interface. The
PIC16F145x family is one of the
cheapest programmable chips with
a USB peripheral. We’ve used the
PIC16F1455 in several projects, most
The USB-C Serial
Adaptor is a minuscule
16×22mm and operates as a dropin replacement for the well-known
CP2102 USB-serial Module. Its USB-C
socket is more robust and modern
than the micro-USB socket on typical
USB-serial modules. The components
are mostly M2012 (0805) size, but still
can be hand-soldered. The USB-C
socket is the finest-pitch part, so
check its soldering thoroughly before
applying power to the board.
notably the Microbridge from May
2017 (siliconchip.au/Article/10648).
The Microbridge provides a similar
USB-serial function as our Adaptor but
can also program PIC32 chips. However, the Microbridge doesn’t break out
the DTR (data terminal ready) signal
like the CP2102 module. The Microbridge also has a different connector
pinout, meaning it is not a drop-in
replacement for the Module.
Circuit details
One of the many types of CP2102based modules, which our USB-C
Serial Adaptor is meant to replace.
Fig.2 shows the circuit diagram of
our new Adaptor. The USB socket,
CON1, is a USB-C type that lacks the
high-speed pairs. That means it only
has one row of pins, making it easier
to solder. The high-speed pairs are not
needed for this design.
We previously used a USB-C socket
with those extra pins in the USB
Cable Tester from the November and
December 2021 issues (siliconchip.au/
Series/374). It had two rows of very
fine pins and was very fiddly to solder; the variant used in this Adaptor
is easier to work with.
The SBU (sideband use) pins are
present on the connector we’re using,
but are not needed in this design and
so are not connected. The two CC pins
(configuration channel) are each connected to ground via 5.1kW resistors,
signalling that the Adaptor is a power
sink (ie, it consumes power rather than
provides power).
The remaining pins on CON1 are
duplicated but are otherwise the same
as used in standard USB 2.0 applications. The duplicated pins are simply
Australia's electronics magazine
June 2024 69
Unlike CP2102
modules, the
USB-C Serial
Adaptor (shown
enlarged) has
components
on both sides,
including
a 1.27mm
(0.05in) pitch
14-pin SOIC
chip and
a handful
of passive
components.
connected together. They exist because
the connector can be plugged in with
two different orientations.
CON2 is a six-way pin header
matching that on the CP2102 modules.
It provides a means to connect to the
logic-level serial signals. 5V power
and ground from CON1 are connected
through to CON2, as well as supplying REG1, an MCP1700-3.3V regulator.
It, and its two 1μF bypassing capacitors, provide the 3.3V supply to match
that on the CP2102 module and so
provide 3.3V logic levels. If you just
wanted to get 5V and 3.3V from a
USB-C cable, you could populate the
Adaptor PCB with just the components
mentioned so far.
PIC16F1455 microcontroller IC1 is
powered at pins 1 and 14 from the 3.3V
rail. There is no separate bypass capacitor because the circuit is physically
very small, and the 1μF capacitor on
the 3.3V rail is close to the requisite
pins on IC1.
As an aside, the PIC16F1454 is
much the same as the PIC16F1455,
except it lacks the analog peripherals
(such as the analog-to-digital converter
[ADC]). We are not using any analog
features, so the two chips are essentially interchangeable in this role.
You should have no trouble using the
PIC16F1454 if you have one on hand.
Power indicator LED3 is fed from
the 3.3V rail via a 1kW current-limiting
resistor. Serial data indicators LED1
(TX) and LED2 (RX) are driven via
1kW resistors from pins 9 and 10 of IC1
(digital outputs RC1 and RC0), respectively. Pin 11 of IC1 is connected to a
100nF capacitor that filters the output
of a regulator internal to IC1’s USB
peripheral.
The USB D+ and D- signal lines
(IC1’s pins 13 and 12) connect to the
corresponding pins on USB socket
CON1 to provide the USB data interface. Pins 5, 6 and 7 on IC1 are connected to CON2 via 220W resistors;
these are the UART RX, TX and DTR
signals, respectively. The 220W resistors protect the microcontroller by limiting the current that can flow through
the pins.
The 100kW resistor provides a weak
pullup on the RX pin, preventing
noise from being seen as data if that
CON2 pin is left unconnected. The
PIC16F1455 lacks an internal pullup
on this pin, so we must provide this
externally.
Software
The USB function is heavily dependent on software. We mentioned the
Microbridge earlier; the Adaptor uses
the same software library to provide
the virtual USB serial port functions.
The library enumerates IC1 as a
CDC (communications device class)
device. CDC encapsulates the features of devices like fax machines and
modems that use a serial interface, so
it is well suited to working as a virtual
USB-serial port.
The Adaptor software also configures pins 5 and 6 of IC1 as the UART
(universal asynchronous receiver/
transmitter) RX (receive) and TX
(transmit) pins. Unlike newer PIC
chips, these functions cannot be allocated to other pins.
Fig.2: aside from its basic functionality, the USB-C Serial Adaptor provides a few niceties, such as independently-driven
TX and RX LEDs, series protection resistors for the data lines and a weak pullup on RX for noise rejection.
70
Silicon Chip
Australia's electronics magazine
siliconchip.com.au
In theory, the Adaptor simply needs
to check the current baud rate, take
data at that rate from the UART RX pin
and send it to the USB host, and from
the USB host to the UART TX pin. In
practice, a few other things need to
happen to make it compatible with
the CP2102 module.
For a start, LED1 is switched on for
about 50ms every time serial data is
received from the USB host. Similarly,
LED2 switches on whenever data is
seen on the UART RX pin.
Having separate lines to drive these
LEDs means that the TX and RX lines
are not loaded unnecessarily. We can
also show a clearer indication that data
is present by lighting the LED longer
than it would be if driven directly by
brief pulses on the serial lines.
The DTR pin is held at a high idle
level and then taken low whenever the
virtual USB port is open; this means
an application is actively connected to
the CDC device. Also, the UART TX
pin is set to a high-impedance state if a
USB host is not connected. The utility
of these functions may not be obvious,
but they have specific uses in applications like the Arduino.
Arguably, modules like the CP2102
USB-serial adaptor exist because of
the Arduino ecosystem. In early Arduino boards (before the Uno!), the DTR
pin on a separate USB-serial adaptor
was used to reset the microcontroller
and enter a bootloader. An RC circuit
turns the high-low transition into a
brief pulse for the micro’s reset pin,
and the bootloader runs for the first
second or so after reset.
The circuit on the Uno R3 works
similarly, although the USB-serial
adaptor is incorporated into the board.
Allowing the TX pin to float if there
is no active connection means the
corresponding RX pin on whatever
is attached can be used for other purposes when not needed for programming since it is not being driven.
USB data is passed in packets at
times dictated by the driver in the
USB host. Data is sent and received
over the bus at 12Mbps (USB fullspeed) during these periods. If transmission and reception are both occurring, this data must be interleaved
over the bus.
Each direction has a 256-byte buffer
to smooth the transition between the
packetised USB data and the continuous UART data. The UART peripheral can also buffer a byte or two of
siliconchip.com.au
data before it gets moved to or from
the main buffers.
The software also monitors for packets requesting changes in the baud rate
or to send a ‘break’ signal. A break is
simply a condition where the TX line
is held low for a time longer than one
byte (the PIC16F1455 does this for 13
bit times). It is often used to synchronise transmission with the receiving
device.
When a request for a break signal is
sent from the computer, the TX LED
flashes for half a second.
Limitations
We have chosen the PIC16F1455
because it is inexpensive, but that is
for a reason. An 8-bit microcontroller
does not have much processing power,
especially for handling the amount of
data that USB can move around.
As such, the Adaptor cannot do
everything that a CP2102 module can.
The UART peripheral on IC1 is limited to 8-bit or 9-bit data, and it does
not natively support parity bits like
the CP2102 chip.
To keep things simple, we only support 8-bit mode. This helps with the
throughput of the Adaptor too, as there
is one less special case to handle. The
current version of the software uses
92% of the 1024 bytes of available
RAM, so there wouldn’t be space to
store the 9th bit for both 256-byte buffers even if we wanted to.
Still, it can handle all the typical
use cases for a USB-serial adaptor,
including very low and very high
baud rates.
Baud rates
The PIC16F1455 has hardware that
uses the USB host’s clock to tune its
48MHz internal oscillator; the available steps result in an oscillator error
of up to 0.2%.
The microcontroller can produce
a wide range of baud rates, from 47
to 3,000,000 baud, from the 12MHz
instruction clock. Our calculations
show that the error in deriving the
baud rate will be less than 0.2% for
the standard rates shown in Table 1.
Thus, the total error in the requested
baud rate compared to the actual baud
rate will be less than 0.4% for standard rates. Any arbitrary baud rate
under 1Mbaud (1,000,000 baud) will
have an error of less than 4%, which
should be sufficient for most applications over short distances.
Australia's electronics magazine
Table 1 – baud rate accuracy
Baud rate Max. error
110 0.20%
300 0.20%
600 0.20%
1200 0.20%
2400 0.20%
4800 0.20%
9600 0.20%
14,400 0.24%
19,200 0.20%
38,400 0.36%
57,600 0.36%
115,200 0.36%
230,400 0.36%
250,000 0.20%
460,800 0.36%
1,000,000 0.20%
Typical
error at
standard
baud rates
(including
0.2% due to
the internal
oscillator).
The throughput of a USB full-speed
connection is 12 megabits per second;
this will not be achieved in practice, as
the USB connection is usually shared
with other devices. Remember that this
also includes data in both directions.
In practice, the limit is much lower,
primarily due to the drivers that limit
the size of the packets that can be sent.
We cannot easily change this, so we
are somewhat stuck with that.
So continuous transmission at
higher baud rates is not possible,
although we had no trouble sending and receiving bursts of data up to
3Mbaud and continuous reception up
to 460,800 baud.
Most of these concerns will not
affect the common uses of these modules, such as acting as a programming
interface for a microcontroller or handling user input (eg, on a Micromite)
at baud rates between around 4800
and 115,200.
Programming
We have omitted a microcontroller programming header to keep
the USB-C Serial Adaptor much the
same size as the CP2102-based modules. Thus, unless you have a pre-
programmed microcontroller, you
should program it before soldering it
to the PCB. If you purchase a kit from
the Silicon Chip shop, IC1 will be programmed, so you won’t have to worry
about it.
June 2024 71
Our PIC Programming Adaptor project from September 2023 (siliconchip.
au/Article/15943) has more information about the gear you might need to
program an SMD chip. Note that you
will also need a PICkit 3, 4 or 5 to do
the programming.
To allow us to quickly reprogram
our prototype during development,
we soldered fine wires directly to the
PIC’s programming pins while it was
mounted on the PCB. That is an option
to consider if you only need to do this
once for this project.
We used the low-voltage programming pins (pins 12 and 13) since the
other programming pins (pins 9 and
10) are loaded by the LEDs, which
could interfere with programming.
Of course, pins 12 and 13 are the
USB pins, so you should not have a
programmer connected at the same
time anything is connected to the
USB socket.
Fig.3: use this diagram and the photos to ensure that the many small
components are all fitted in the correct locations. Take care that IC1 is installed
the proper way. If you look from the end of the chip, you should see the
chamfered edge on the pin 1 side.
a PCB, you might prefer a straight
header.
If you are adding the Adaptor to a
low-power design, you could omit the
LEDs to save on the current they would
draw. In that case, you could also omit
the 1kW resistors. The 100kW resistor
could also be left off if you are sure
that the RX pin will always be in a
well-defined state.
Construction options
Construction
We’ve specified a right-angled
header for CON2 since that is what
most CP2102-based modules are supplied with. If fitting the module to
You’ll need all the standard gear for
SMD work, including a good magnifier.
This is one of the smaller projects we
have created, and it packs the parts in
fairly tightly. You might need a magnifier even to read the PCB’s silkscreen
markings.
Make sure you have solder flux (ideally as a paste), tweezers, a fine-tipped
iron and a means of securing the board,
such as Blu-Tack. Fume extraction (or
working outside) will help remove
flux smoke. You should also have a
suitable solvent for cleaning up the
PCB afterwards, and solder-wicking
braid will be helpful in case a solder
bridge forms.
The USB-C Serial Adaptor is built on
a double-sided PCB coded 24106241
that measures 16×22mm. We’ll refer
Songbird
An easy-to-build project
that is perfect as a gift.
SC6633 ($30 plus postage): Songbird Kit
Choose from one of four colours for the PCB (purple, green, yellow or red). The kit includes nearly all
parts, plus the piezo buzzer, 3D-printed piezo mount and switched battery box (base/stand not
included). See the May 2023 issue for details:
siliconchip.au/Article/15785
72
Silicon Chip
Australia's electronics magazine
siliconchip.com.au
to the side with the USB-C socket as
the top of the PCB, with microcontroller IC1 at the bottom. The overlay diagram, Fig.3, should help you place the
small components.
USB-C socket CON1 has the finest pin pitch of the parts used, so fit
it first. Add a thin layer of flux to the
PCB over its pads, then position the
socket. There are holes to help align it,
and you can add more flux to the top of
the pins too. Tack the larger end-most
pins and confirm that the other pins
are aligned with their pads and that
the socket is flat on the PCB.
You can then solder the mounting
pins to secure the location. Add flux
to the tops of the mounting holes and
apply the solder from below until it
can be seen wicking up the pins to the
top side. That way, you know this part
is properly secured and won’t easily
be torn off the PCB.
Now solder the remaining pins of
CON1. If you get a bridge between two
pins, add a little more flux and use
solder-wicking braid to draw it up. If
you’re unsure about your soldering,
clean up the flux to get a better view
of the pins under magnification before
proceeding.
Solder REG1 in place next. This is
on the same side of the PCB as CON1.
Apply a little flux to the PCB pads
and tack one lead, then check that the
other leads are aligned before soldering them. That is the basic strategy
needed for the remaining SMD parts.
This side also has the three LEDs
and their 1kW resistors. LED1 is blue
and is fitted adjacent to the TX pin on
CON2, while LED2 is red and is nearer
to the RX pin. LED3 is green. While it
wouldn’t be a tragedy if you mixed up
the colours, we tried to make them easier to remember (eg, red and RX both
start with the letter R).
LED1 and LED2 have their cathodes
towards the USB-C socket. The cathode is usually marked with a small
green dot or something similar, but it’s
best to check with a DMM set on diode
test mode. When you touch the probes
to the LED pads and it lights up, the
red probe is on the anode, while the
black probe is touching the cathode.
LED3 faces the opposite direction.
Next, solder the 1kW resistors and
then one of the 1μF capacitors, which
should be the last SMD part on this
side of the PCB.
Next, flip the PCB over and fit IC1.
The technique is much the same,
siliconchip.com.au
Parts List – USB-C Serial Adaptor
1 double-sided PCB coded 24106241, 16×22mm
1 SMD USB Type-C socket with power & USB 2.0 data (CON1)
[GCT USB4105 or equivalent]
1 6-way right-angle pin header (CON2)
Semiconductors
1 PIC16F1455-I/SL microcontroller programmed with 2410624A.HEX,
SOIC-14 (IC1)
1 blue SMD LED, M2012/0805 size (LED1)
1 red SMD LED, M2012/0805 size (LED2)
1 green SMD LED, M2012/0805 size (LED3)
1 MCP1700-3302 3.3V low-dropout linear regulator, SOT-23 (REG1)
Capacitors (all M2012/0805 X7R, 10V or higher)
2 1μF
1 100nF
Resistors (all SMD M2012/0805 size, 1/8W, 1%)
1 100kW
1 10kW
2 5.1kW
3 1kW
3 220W
although its pins are smaller than
those on the resistors and more closely
spaced (although more widely spaced
than the USB socket). Make sure you
put it in the right way around, with
pin 1 orientated as shown!
Apply flux to the PCB, place the
chip with tweezers and tack one lead.
Check its alignment, then solder the
other leads.
It is best to fit the other 1μF capacitor next so that it doesn’t get mixed up
with the 100nF capacitor that mounts
next to it. The other seven parts are
an assortment of resistors; ensure the
correct values go in the right places,
as shown in Fig.3.
Now use a solvent to clean off any
flux residue, allow the board to dry,
then inspect it closely for bridges or
dry solder joints. If everything looks
good, you can solder your choice of
CON2 and proceed with testing.
Testing
Try connecting the Adaptor to a
USB supply. If you are not confident,
don’t connect it to a computer, but
use a USB power supply or something
similar. You should see green LED3
illuminate within a second or so. If it
does not, disconnect the Module and
recheck the component placement
and soldering.
You could try flipping the USB-C
cable to see if it makes any difference.
If it does, that points to a problem with
CON1 or the two 5.1kW resistors.
While it is plugged into a power
source, use a voltmeter to measure the
3.3V and 5V pins on CON2 relative to
GND. A lack of 5V indicates a problem with CON1 or the 5.1kW resistors.
Australia's electronics magazine
If 5V is present but 3.3V is not, there
could be a problem with the regulator, or perhaps another component is
shorting the 3.3V rail.
Once everything is working, connect the Adaptor to a computer and
check that a new serial port is available. Use a program like TeraTerm or
minicom to open the port and send
some data by typing in the terminal
window. You should see blue LED1
(next to TX) flash.
If you connect the RX and TX pins
on CON2 (eg, using a jumper cable)
and send data, the red and blue LEDs
should flash together as data is being
looped back. Your terminal should
echo the characters you are typing.
If this is all as expected, the USB-C
Serial Adaptor is working and can be
deployed to your project.
Using it
The USB-C Serial Adaptor is generally a drop-in replacement for the
CP2102 modules that it is intended to
succeed. Like those modules, we use
it to power and connect to projects for
debugging purposes.
We have also incorporated such
modules into projects, such as the
ESP32-CAM LCD BackPack (April
2024; siliconchip.au/Article/16212).
You can use the USB-C Serial Adaptor
instead of the micro-USB Type-B version specified in that project.
Our Adaptor has some components
on the bottom side, unlike the CP2102
modules, so it will need to be spaced
away a little from the host PCB. The
plastic insulation on standard pin
headers should be sufficient for that
purpose.
SC
June 2024 73
|