Converter rs232 to usb on chip pl2303. USB-UART to CH340G converter: upgrading to RS232TTL, testing, comparing

Microcontrollers in Arduino (ATmega328, 168, 2560) use, among other interfaces, a hardware-implemented serial interface (UART). The ATmega2560 MK (Arduino Mega) implements four UARTs at once. The interface uses two wires - RX (receive) and TX (transmit), where the digital signal encodes the bit values ​​"0" and "1" with the voltage on the wire. The value "0" corresponds to 0V, and the value "1" corresponds to the operating voltage of the integrated circuit (5V or 3.3V, depending on the model and mode of operation of the MK). This type of coding is also called transistor-transistor logic (TTL). the voltage on the wire directly affects the state (open / closed) of transistors that provide digital signal reception and transmission.

The computer serial port (COM port), which is rarely seen in modern models of compact computers, operates according to the old telecommunications standard RS232, where the signal encoding is different: the value "0" is encoded with voltage from + 3V to + 25V, and "1" - negative voltage from -3V to -25V. In COM ports of personal computers, voltages of +13V and -13V are usually found.

A large voltage difference makes the RS232 connection more resistant to interference, however, in modern digital devices, a TTL-compatible serial port is more often used, or USB - a much more modern and high-speed interface.

For comparison, the figure below shows the TTL serial and RS 232 signals taken when transmitting the value of one byte.

To convert the RS232 signal to TTL and vice versa, you need to invert it (although this can be done in software) and convert the voltage. Typically, microcircuits such as MAX232 are used for this. Sometimes they use simplified home-made circuits that provide signal inversion and voltage conversion, or resort to software and hardware solutions (software inversion, hardware voltage change).

In the case of Arduino (Uno, Mega, etc.), a USB-TTL serial controller is used, which provides work with the MK via a TTL-compatible serial interface. In older models, the FTDI FT232 chip was used for this, in the new ones - ATmega8U or ATmega16U. The MK serial interface pins are also available for direct connection. For Uno, these are pins D0, D1, and the Mega model has several serial interfaces at once. You cannot connect the RS232 port to these pins - it will not be able to work correctly due to a different type of coding, and high voltage can damage the MK.

To connect to a TTL-compatible serial port from a computer, it is convenient to use a USB-TTL serial adapter. However, general-purpose USB-TTL serial adapters are sold only in specialized stores and often at an unreasonably high price. At the same time, USB-RS232 adapters are much more popular (and cheaper). On closer examination, any USB-RS232 adapter contains two main components - USB-TTL serial adapter chips and RS232-TTL serial converter.

I found a USB-RS232 adapter, the circuit of which was hidden in an easily disassembled DB9 connector housing (sometimes the housing is cast and it is more difficult to get to the circuit). The adapter turned out to be built on the popular Prolific PL2303 (USB-TTL serial adapter) and Zywyn ZT213 (RS232-TTL adapter) chips. Looking at the PL2303 specification, I found out that I needed pins 1 (TX) and 5 (RX), to which I soldered the wires without changing the circuit in any way (so the RS232 part remained operational). I took the earth from the 5th pin of DB9, so as not to touch the 7th pin of the microcircuit.

The result is a cheap and angry USB-TTL serial adapter. In the screenshot: Serial monitor from Arduino IDE is connected via USB, and realterm is connected directly to D0,D1 via USB-TTL serial adapter.

I heard that many data cables for mobile phones also contain USB-TTL serial controllers, although an increasing number of modern models connect directly to the USB interface without requiring special adapters. Many microcontrollers are equipped with a USB interface, in particular the ATmega8U and ATmega16U, which are used by the Arduino as USB-TTL serial controllers, providing access to the ATmega328, which does not have a USB interface.

PL2303HX is a small USB-to-Serial converter with built-in RS232 transceiver (UART interface). The microcircuit creates a virtual COM port on the computer, through which you can flash microcontrollers, as well as restore routers and set-top boxes.


Technical specifications

Supply voltage: 5V (from USB)
Interface 1: USB
Interface 2: TTL (0 to 5, Rx and Tx)
Output voltage, V: 3.3 and 5 (separate outputs)
Dimensions: 50mm x 15mm x 8mm
Operating system support: Windows XP / 7 / 8 / 8.1 / 10.

General information about PL2303HX

The main chip per module is PL2303HX, which until 2012 was produced by Prolific Technology. In fact, this is a USB to UART interface converter with TTL, CMOS (0 V ... +5 V) logic levels. On the one hand, a USB connector for connecting to a computer, and on the other, a five-pin UART connector (RX, TX and power outputs for + 5V and + 3.3V), for short circuit protection, the module is placed in a transparent heat shrink tube, the PL2303HX circuit diagram is shown in the figure below.

Purpose of the LEDs:
P (Power) - power (solid on)
R (RxD) - received data
T (TxD) - transmitted data

It can be seen from the electrical diagram that the + 5V output is powered directly from the USB port, without protective elements, and the + 3.3V output is powered from the internal PL-2303 stabilizer, which can withstand current up to 150 mA. The official Prolific drivers for Windows 7, 8 and 10 does not work since. checks the originality of the PL-2303 chip, but it is possible to fix everything by looking at this .

Testing

For testing, you can use Terminal1_9_b", you can download this program in this article.

Install, driver
We launch "Terminal1_9_b" on behalf of the administrator.
In the top corner, select " COM port" (can be viewed in the device manager) and click " Connect»

Below, enter an arbitrary value and click " -> send“, the TxD LED will light up briefly with each press.
Short the TxD and RxD pins together and press "-> Send", two LEDs, TxD and RxD, will briefly light up with each press, and the program will display the sent command.
Voltage 3.3V and 5V can be checked with a conventional multimeter

Links
Documentation PL2303HX
Driver for

I had to output data from the GGA and VTG packages to the LCD, which is not very convenient given the maximum package size of 80 characters.

When debugging, I had to output data from the GGA and VTG packages to the LCD, which is not very convenient with a maximum package size of 80 characters.

Such disgrace was due to the fact that I had, which was inconvenient to use, in which something was always short and threatened the precious COM port on my PC. I wanted to make a brand new, pretty one, in a cute case and with beautiful wiring :) A scarf was etched, the wiring of which can be downloaded at the end of the note.

Further, the board was installed from ST Microelectronics (a complete analogue), but cheaper by a couple of hryvnias. Of course, I respect Maxim, but I absolutely do not like to overpay for trivial things. Capacitors in the harness set to 1uF 16V tantalum, type A.


Further, this whole household was shoved into the building, which I had been lying around idle since I was 13 years old. I protected the wires from pulling out with a simple knot. A soft cable with a connector for the COM port was borrowed from an old mouse.


A sticker was printed with the designation of the wiring and pasted on the case so as not to constantly remember where the plus and where the minus is :). A layer of adhesive tape protects it from abrasion. Now the converter has acquired some usability, and it has become convenient to use. Have a nice day.

Almost all microcontrollers have a serial port on board - UART. It works according to a standard serial protocol, which means it can be easily connected to a computer on COM port. But there is one problem here - the fact is that the computer RS232 he takes for logical levels +/- 12 volt, a UART operates at five volt levels. How to combine them? For this, there are several options for level converter circuits, but the most popular is still on a special converter. RS232-TTL. This is a microchip MAX232 and its analogues.
Almost every company makes its own converter, so it will fit here ST232, and ADM232, and HIN232. The circuit is as simple as three pennies - input, output, power and piping of five capacitors. Capacitors are usually placed 1uF electrolytes, but in some modifications 0.1uF ceramics. I soldered everywhere 0.1uF ceramics and usually this was enough. :) Works like a clock. If at high speeds it will fail, then it will be necessary to increase the capacity.

By the way, there is also MAX3232 this is the same, but at the output it does not have 5 volts TTL, but 3.3 volts TTL. It is used for low voltage controllers.

I made myself one such universal cord so that it would be convenient to cling to the controllers by UART. For overall compactness, I shoved the entire circuit straight into the connector, since I had ST232 in soic case. The result was a handkerchief no more than a ruble coin. Since there were no small SMD capacitors at hand, I had to solder the conders from above, whoever was in what much. The main thing works, although it did not turn out very beautifully.


If you doubt that you will succeed in such a small installation, then I have divided the board for you into a standard PDIP case. It will be the size of a matchbox, but you don’t need to grind.


After assembly, it is simply checked:
Plugs into socket COM port. Apply 5 volts of power to the circuit, and then close Rx on the Tx(I have green and yellow wires).

Then you open any terminal, at least HyperTerminal, cling to the port and start sending bytes, they should immediately come back. If this does not happen, check the circuit, somewhere there is a jamb.

If it works, then everything is simple. The wire that comes from pin 9 of the chip MAX232 This transmitting output, get him on his leg RxD controller. And the one from the leg 10 - receiving, feel free to put him on the conclusion TxD controller.

Through some simple manipulations (the description of which is more suitable for habr), both the bootloader and the arch were installed on the memory card and the device was turned on. However, after loading, I was waiting for a black screen and a burning green LED on the "orange".

Well, no problem, I thought. UART is soldered on the "orange", I'll connect to it with a terminal and see what happens. The necessary parts and wire were bought and such a cable was soldered (picture under the spoiler)

Nubian cable option


Anyone who is in the subject will immediately understand what I was wrong by making such a cable, and there are more than half of those among those who read. I suspected something was wrong after I saw the krakozyabry that my "orange" spat into the terminal. It was the understanding of the cause of my stupidest mistake that prompted me to take the actions described below.

1. What is the difference between UART and RS232

Level difference. The serial interface implemented in the Orange Pi and similar devices is based on TTL logic, that is, a zero bit corresponds to a zero voltage level, and a one to a level of +5 V. RS232 uses a higher voltage level, up to 15 V, and a unit corresponds to - 15 V, and zero +15 V. To increase the noise immunity of the channel, any voltage level below 3 V modulo is perceived as zero. The data transfer protocol at the level of the sequence of logical values ​​​​is absolutely the same for both UART and RS232. All this is illustrated by the following byte transfer diagram.

How could I forget about it? When I was working at the Electric Locomotive Research Institute, I knew these things. And then for some reason stupidity froze. In general, it became clear that a certain level converter with signal inversion was needed. The choice fell in the direction of connecting the entire household to the COM port, which is on the motherboard of my home computer. Although of course you could look in the direction of UART<->USB, because the old serial interface is steadily losing relevance. However, my penchant for simpler solutions won out and such a device surfaced as a candidate for purchase

Sold on the same Ali for 464 rubles. In principle, this could be found in stores or at the radio market in my city, but the itch to do something with my hands was already awakened. So I dismissed the idea of ​​buying an interface board and decided to try and make one myself.

I must say that I'm actually friends with a soldering iron. At school and university, before buying the first computer, soldering all sorts of useful and not very nonsense was my main hobby. But I lived in the village, it was the nineties. There was not much money, the components were obtained by dismantling the radio junk that came into view. The source of information was books from the district library - not everyone had the "Internet" then. There was no rich instrument either. Foil textolite and ferric chloride were a legendary miracle. In general, it was difficult.

After buying a computer, all the enthusiasm switched to it. And the soldering skill of small receiver amplifiers is put on the shelf. So I'm a teapot. Therefore, much of what I will write about below, I ask you to treat indulgently. And this article, by and large, is for the same "dummies" like me.

2. Choice of device scheme and its computer simulation

Find a diagram of such a device on the net just to spit. There are many such schemes. The choice fell on this

The heart of the whole device is a MAX232 type microcircuit - a level converter operating on the principle of a "charge pump". The voltage increase from 5 V is carried out by alternately charging external capacitors C4 and C5. At the moment of issuing a signal to RS232, these capacitors are connected in series, and the voltage accumulated in them adds up. During the reverse transmission, the microcircuit works as a divider. In both directions of signal transmission, it is inverted.

Diode VD1 plays the role of "fool protection" - it locks the power circuit when a voltage of the wrong polarity is applied.

Before proceeding with the manufacture of the device, I decided to see how it all would work, so I started by modeling the future device in the Proteus environment. To test the circuit, a virtual stand was assembled

The first thing I wanted to do was to simulate everything, including the power circuits, since I was interested in the effect of the diode on the operation of the circuit. By default, in Proteus, the power pins on the microcircuits are hidden and pulled up to the plus of the desired level and ground. To unlock them, you first need to display the hidden pins. To do this, go to the menu Template -> Set Design Colors and check the box Show hidded pins

In which we put the checkboxes Draw body and Draw Name. After that, select the entire microcircuit, including the text with which the conclusions are signed, and right-click the menu, select Make Device. We will be asked to choose a name for the new device and save it. Everything, after that the power circuits will be included in the simulation process explicitly.

Further, we will transmit something meaningful via UART, for example, the letter “A” encoded in ASCII by the code 65 in decimal number system or the sequence 01000001b in binary. In addition, to initiate a transfer, it is necessary to send a start bit with a level of "0", and to complete the transfer, send one or two stop bits with a level of "1". Thus, the timing diagram of a frame transmitted via UART will look like this

To form such a signal, we use a source called Digital Pattern Generator (DPATTERN) with settings of the form

A pulse width of 104 microseconds corresponds to 9600 baud. The waveform is given by a string pattern where "L" means low and "F" means high. Accordingly, our line will look like "FLFLLLLLFLF". We will control the data received in RS232 by a virtual terminal, configuring it like this

We will not use the parity bit, and will use one stop bit. In addition, let's say that the signal applied to the terminal is inverted, which corresponds to the RS232 protocol. By running the simulation of the circuit, we obtain an oscillogram of signals and output to a virtual terminal

Channel A carries the output signal to the COM port. On channel B - input TTL signal. The cherished letter "A" is displayed in the terminal. Thus, we are convinced that the proposed scheme is quite efficient. In theory.

3. Selection and purchase of components

Of the stores closest to my habitat where you can get hold of radio components, there are two worthy of attention: the Radio Parts store on Budenovsky Prospekt (this is the city of Rostov-on-Don) and the 1000 Radio Parts store on Nagibina Avenue, opposite the Rio shopping center. The latter compares favorably with the fact that he has a site, though quite ancient, and apparently lazily updated (and made on Joomla...). Crawling through the price list, I picked up a list of what I need to buy.

I must say right away that I carefully avoided SMD components due to my inexperience. That's why I chose the MAX232CPE through hole mount. I took the same electrolytes and a diode. However, in place it turned out that only the MAX232CWE chip is available - the same thing, only ... SMD! After thinking for a second, I agreed with the seller's proposal - we must start sometime ... There were no 15 V capacitors, but there were 100 V capacitors of the same capacity and the same dimensions. Okay, nothing too. Instead of a DB-9 male connector, I was offered a female. This resulted in the following list

Ferric chloride, zapon varnish and textolite, of course, were not fully used. In addition, I did not include the purchased tool in this list: a simple soldering station (because before that I had only a 40-watt soldering iron with a copper tip), side cutters and small pliers, metal scissors for cutting textolite, liquid rosin-alcohol flux LTI-120 well etc. In general, this epic cost me about 3000 rubles.

In general, the components were purchased and brought home. The 40-pin PLS pads were cut to the correct number of pins. One of the contacts is taken out in order to ensure the uniqueness of the connection. The hole in the socket corresponding to the removed pin is sealed with polyethylene.

4. Assembling the device on the breadboard and checking the operation

In principle, for such a simple device, this is not necessary. But I'm a "teapot", so before making a board, I decided to check the circuit in real work.

The most difficult thing was with the microcircuit. To solder it to the breadboard, I had to pervert with soldering twelve legs to copper conductors. Out came the spider monster with twelve legs

At that moment, I realized two things: it's good that I still bought a soldering station. And the bad thing is that I have to pretty tinker with this small thing. In general, the components were soldered to the "breadboard", the circuit was assembled with an "orange" board. +5 V power taken from the "orange" - 2nd pin on a two-row 40-pin pin block

To connect to the device, the putty terminal was used, which is also available under Linux, and, unlike minicom, has a colored output and does not require additional configuration for entering characters into the terminal from the keyboard.

In general, the board worked - the lines of the boot log ran across the terminal screen: first from u-boot and then from the linux kernel

Needless to say, I was delighted: firstly, the scheme works correctly, and secondly, Linux on the “orange” is installed correctly, it works normally in multi-user mode

The inoperative HDMI connector and the lack of an Ethernet interface, therefore, are due to the configuration of the distribution itself. These problems, of course, will be solved and this is not about them. So let's move on to the next step of the program.

5. PCB layout

Made it in Altium Designer. The layout of the board is best done after the components are purchased. It may be necessary, as in my case, to install additional component libraries for Altium. The dimensions of the components and the topology of the footprint for each must match the actual parts available. Here I was not without an unfortunate oversight, but more on that below.

I will say right away - do not use automatic wiring. Perhaps this is configurable, but the auto-wiring strove to drag a track between the legs of the capacitors, which, with a distance of 2 mm between them, makes the track about a quarter of a millimeter wide, which was too cool for me as a “teapot”. Yes, and intuition suggested that it is desirable to avoid such things. Therefore, I used manual routing (based on the results of the automatic one), setting the width of the roads to 0.5 mm in the routing rules (Design -> Rules -> Routing -> Width)

Also, Altium assumes that the board is dual-layer by default. To force it to wire a single-sided board in the wiring rules, you must specify the wiring in one layer, say in the Top Layer

The scheme was typed in the scheme editor

When doing this, one must take into account the fact that the free unsoldered inputs of the microcircuit (legs 8 and 10) must be pulled to the ground, otherwise Altium will not compile the schematic for transferring it to the PCB editor.

As a result, by independent picking in the program and Alexey Sabunin's lessons the goal was achieved and the fee was divorced

All components with mounting through the holes are located on the clean side of the textolite, and the microcircuit, due to the SMD version, is on the side of the tracks. To print the layout of the circuit, you must create a so-called Output Job File in the device project

Which is configured as follows. In the list of configuration options, select Documentation Output and click on Add New Documentation Outpu, selecting from the menu that appears PCB Prints and the PCB project related to our device.

We rename the documentation item that appears, let's call it LUT, according to the transliteration of the technology (LUT), which we are going to use to transfer the board pattern to copper. Right-click on the LUT and select Configure from the context menu. In the settings of the layers to be printed, we leave only two items: Top Layer and Multi-layer and arrange the checkboxes as shown in the screenshot

The Mirror checkbox is needed, in particular, to mirror the image on the printout. This is important, otherwise, when transferring the pattern to copper, we will get a mirror image of our tracks, but we don’t need it. In addition, you should look into Page Setup

To select the paper size and pay attention to the scale factor (Scale). At the first print, it turned out to be equal to 1.36 for some reason, but it should be equal to one

Now click Print. I don't have my own printer, so I printed to PDF using Foxit Reader, and then took the resulting file on a USB flash drive to the nearest "sharashka", in which I printed the drawing on glossy photo paper. In the end this is what happened

The size of the board came out 62 x 39 mm, a piece of textolite was cut to this size with metal scissors. I used to saw textolite with a hacksaw and often (or rather always) it turned out terribly. With scissors, it comes out evenly, without debris and damage to the conductive layer.

6. PCB manufacturing

The LUT method (laser ironing technology) was chosen because of its simplicity and accessibility. Served as a guide to action. I tried not to violate the technology: I walked through the copper with a zero, degreased it, though not with acetone, because I could not find where to buy it, but with a universal degreaser based on white spirit, bought at Lerua Merlin. Carefully and with effort I ironed a sandwich made of textolite and a pattern with iron at maximum temperature. Either because I made a mistake somewhere, or because I didn’t let the workpiece cool down, or just in the “sharashka” they save toner on the printer, in general, it didn’t work out very well

However, I prudently stocked up with a permanent marker Edding 404, which, not without the help of my beloved wife (with a pumped skill for drawing eyelashes and drawing patterns on nails), circled all the tracks

Next, a solution of 6-aqueous ferric chloride was diluted at the rate of about 180 grams per 300 ml of water (I took hot water from the tap) and the board was thrown into a etching cuvette to be eaten. In order to pickle the board and not poison his wife at the same time, the operation was performed at sunset on the balcony

"Khlonyak" did not disappoint, there are rumors that they often sell low-quality ones. Etching took 13 minutes, the last islands of copper left right before our eyes. The main thing is not to forget to periodically kick the board with tweezers along the cuvette and monitor the process. As soon as the excess copper disappears, we take out the board urgently and rinse it with a plentiful stream of water.

After washing, wiping and drying, the moment of truth comes. You need to remove the protective cover. I tried to do it with white spirit

But things were going rough. Then my wife offered her nail polish remover - this miracle elixir washed off the coating instantly (I'm still horrified by what reagents our women use. Beauty is a terrible force!)

The marker did not disappoint - all tracks survived

After cleaning the protective coating, you can start drilling holes. And here I made an unfortunate mistake - I didn’t have a 0.5 mm drill, and instead of postponing the matter until tomorrow, having bought the right drill, I hurried up and took a millimetric one, considering that it would fit. As a result, I damaged many contact pads, fortunately not much and not irrevocably. But still, never rush. As my friend Mark from the laboratory of the Department of Mechatronics at the University of Munich, where I did my undergraduate practice, said, “Dmitry, take the right tool for each job.” And he was a thousand times right.

7. Board tinning and component soldering

The soldering points of the components should be covered with a thin, shiny layer of solder. This is the main condition for the success of the work. I didn't tinker with the entire tracks. Firstly, I was afraid to warp them, and secondly, I was still going to cover the zapon board with varnish. So I only irradiated the solder points. To do this, we apply LTI-120 rosin-alcohol flux on them with a brush and with a soldering iron heated to 250-300 degrees, from the tip of which a tiny drop of solder hangs, we draw along the necessary points of the board. By increasing the surface tension of the flux, the solder spreads over the exact pads.

After that, the “breadboard” was disassembled, the wiring was removed from the microcircuit, and it was soldered first of all. Gently place the microcircuit in its place with hands or tweezers in accordance with the pinout, so that each leg takes its own area. Then we lubricate the rows of legs with flux. With short and precise movements, we touch all the legs in turn, not forgetting to collect solder on the soldering iron tip (but not too much, a small drop is enough). If everything is done correctly, then the legs are soldered to the site very quickly and accurately, without “snot” and bridging neighbors. It took me less than a minute to seal the chip, and this is my first time doing it. Inspired me to do this such a video for which I am very grateful to its author. Everything turned out really not so scary.

Similarly, I figured out the rest of the details. The main thing here is to carefully cut the leads of the parts to the desired length - I left no more than a millimeter of the lead sticking out above the track, and bend them correctly and carefully, if necessary. It is important, it is extremely important not to rush anywhere and do everything thoughtfully. In the end, what happened

It was not possible to get away from the “snot”, but for the first time it turned out quite tolerably, although I will probably be criticized.

8. Checking circuits and another annoying mistake

After soldering, we wash off all the flux with alcohol, pick up a multimeter and call all the circuits in order to check their conductivity and compliance with the circuit diagram. And here the byaka crept imperceptibly. The COM port connector turned out to be mirrored! "Earth" sat on the first leg instead of the fifth, Rx - on the fourth instead of the second. And I still don’t understand how, because everything was correct when wiring in Altium. This has remained a mystery to me. No mystery - just having the "mother" connector in fact, when forming the circuit in Altium, it still used the "dad". Hence the mirror wiring, which turned out as a result. Fortunately, I solved this problem by appropriately soldering a cable designed to connect the device to the computer's COM port. But because of this error, the COM on the board turned out to be so “proprietary”.

Otherwise, the installation turned out to be correct and, having unsoldered the connecting cables and tidied up the workplace, I connected a brand new board to the "orange" and the computer

The boot log lines ran across the terminal window again. I was happy!

9. Bringing "beauty"

In order to protect the contacts from oxidation and give the device an “industrial” look, the board was painted with green lacquer. All the marks applied before installation with a permanent marker were washed off by this same varnish. Well, okay ... Here is a photo of the finished product along with a set of cables

Now you can proceed to further refinement of the software for the "orange". Now I will not be blind and dumb, but will be able to set up the system through a serial terminal.

Conclusion

That was interesting. Interesting for me, because for the first time. The first device designed on a computer and assembled on a printed circuit board with your own hands. And if someone smiles ironically, then let him remember that he, too, once did it for the first time ... Add tags

Share