⬆️ ⬇️

How the "maker" did a UART <-> RS232 converter for Orange Pi

Introduction





It all started with the fact that I bought myself an Orange Pi, succumbing to the advertising slogan "analogue of the Rasberi Pi for only $ 15." The device was ordered on aliexpress and arrived fifteen days later in February. At the same time, all the necessary additional components were purchased: a radiator for a processor, a 15 watt power supply unit, a 32GB micro SD card, an HDMI cable for connecting a monitor. For lack of time, he was gathering dust in the drawer of the table until June. And finally got his hands to check its performance.





')

On the standard firmware offered on the official website, the operability did not cause any complaints. But the standard firmware does not suit me for the reason that I’m so arranged — any device that came into my hands must be customized in full. Therefore, U-boot was taken into the hands, the source code of which was downloaded from official FTP , as well as the build of Arch Linux for ARM . This manual for Banana Pi was taken as the reference manual and the starting point for digging.



By some simple manipulations (the description of which is more suitable for the habr), both the bootloader and the arch were uploaded to 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, never mind, I thought. On the "orange" soldered UART, I connect as a terminal to it and see what happens. Were purchased the necessary parts and wire and soldered such a cable (picture under the spoiler)



Noob cable






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



1. What is the difference between UART and RS232





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







Here is how I could forget about it? When I was working at the electric locomotive research institute, I knew these things. And then for some reason, stupidly froze. In general, it became clear that we need a level converter with signal inverting. The choice fell towards connecting the entire farm to the COM port, which is on the hardware of my home computer. Although of course you could look in the direction of UART <-> USB, because the old serial interface is steadily losing its relevance. However, my penchant for simpler solutions won out and such a device surfaced as a candidate for acquisition.







sold on the same "Ali" for 464 rubles. In principle, this could be found in stores or on the radio market in my city, but the itch to do something was already awakened by the hands. Therefore, I rejected the idea of ​​buying a pairing board and decided to try to do it myself.



I must say that I'm actually friends with a soldering iron. In school and university, before buying the first computer, soldering anything useful and not very nonsense was my main hobby. But I lived in the village, there were nineties. There wasn’t much money, the components were taken in by disassembling radio-log in sight. Books from the regional library were the source of information - 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 the computer all the enthusiasm has switched to it. And the skill of the soldering iron of small amplifiers-receivers is put on the shelf. So I am a "kettle". Therefore, much of what I will write about below, I ask is indulgent. And this article, by and large, for the same "dummies" like me.



2. The choice of the circuit device and its computer simulation





The scheme of a similar device found on the network once spit. There are really many such schemes. The choice fell on such a decision







The heart of the entire device is a MAX232 type microcircuit - a level converter operating according to the " charge pump " principle. Increasing the voltage from 5 V is carried out by alternately charging the external capacitors C4 and C5. At the moments of signal output to RS232, these capacitors are connected in series, and the voltage accumulated in them is added. During postback, the microcircuit works as a divider. In both directions of signal transmission, it is inverted.



Diode VD1 plays the role of "protection against a fool" - locks the power circuit when the supply voltage of the wrong polarity.



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







The first thing I wanted to do was to model everything, including the power supply, 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 chips are hidden and pulled up to the plus level and ground. To unlock them, you must first display the hidden pins. To do this, go to the menu Template -> Set Design Colors and set the Show hidded pins checkbox







Next, click the right button on the chip and select (most recent) Decompose. The chip will be disassembled into separate parts. Double click on the desired pin will display the window







In which we put the daws Draw body and Draw Name. After that, select the entire microcircuit, including the text that signed the conclusions and select Make Device with the right button of the menu. We will be asked to choose a name for the new device and save it. Everything after this power supply will be included in the simulation process clearly.



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







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







A pulse width of 104 microseconds corresponds to a speed of 9600 baud. The waveform is defined by a string pattern where "L" means low level, and "F" - high level. Accordingly, our string will look like “FLFLLLLLFLF”. We will control the data received in RS232 by a virtual terminal, setting it up







We will not use the parity bit, and we will use one stop bit. In addition, we say that the signal supplied to the terminal is inverted, which corresponds to the RS232 protocol. By running the circuit simulation, we obtain the waveform of the signals and output to the virtual terminal







Channel A is the output signal supplied to the COM port. On channel B - input TTL-signal. The treasured letter “A” is displayed in the terminal. Thus, we are convinced that the proposed scheme is fully functional. In theory.



3. Selection and purchase of components





From the stores closest to my habitat where you can get hold of radio parts there are two noteworthy ones: Radio Parts Store on Budenovsky Avenue (this is Rostov-on-Don) and Shop 1000 Radio Parts on Nagibina Avenue, opposite the Rio Shopping Center. The latter compares favorably with the fact that it has a website , albeit a rather ancient one, and apparently lazily updated (and made on Joomla ...). Crawling on the price, I picked up a list of what I need to buy.



I must say, I carefully avoided the SMD components due to my inexperience. Therefore, I chose the MAX232CPE in perforation mounting. I took the same electrolytes and a diode. However, it turned out that in the presence of only the MAX232CWE microcircuit is the same, only ... SMD! Thinking for a second, I agreed with the seller’s proposal - we had to start sometime ... There were no 15 V capacitors, but there were 100 V capacitors of the same size and dimensions. Well, nothing, too. Instead of a DB-9 “dad” type connector, I was offered a “mother”. Thus the following list has turned out.



PositionQuantity, pcsCost, rub
MAX232CWEone70
Electrolytic capacitor, 1 microfarad x 100 Vfour15
Diode 1N4148onefive
Socket DRB-09FAone20
DB-9F socketone20
DB-9M plugone20
Enclosure for DB-9 connector220
Pins pls-40one15
PLS-40 socketsone15
Textolite unilateral 200 x 200 mmone200
Tsapon varnish green, 30 mlone50
Chloric iron 6 water, 250 gone160
Total :655




Chloric iron, tsapon varnish and textolite, of course, were not fully used. In addition, I did not include the acquired tool in this list: an unpretentious soldering station (for before it had only 40 watt soldering iron with a copper tip), side cutters and small pliers, metal shears for cutting textolite, liquid rosin-alcohol flux LTI-120 well and so on. In general, this epic cost me about 3000 rubles.



In general, the components were bought and brought home. 40-pin PLS-pads were sawed off under the desired number of contacts. One of the contacts is taken out to ensure uniqueness of the connection. The hole in the socket block 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 it is not necessary. But I am a “kettle”, so before making a fee, I decided to check the circuit in real work.



The hardest thing was with a microcircuit. In order to solder it to the mock-up board, it was necessary to pervert with the soldering of twelve legs to the copper conductors. Spider monster about twelve legs







At that moment I understood two things: it’s good that I still bought a soldering station. And the bad thing is that I have to pretty much tinker with this small fry. In general, the components were soldered on a “breadboard”, the circuit is assembled with an “apellus” board. Power supply +5 V taken from the "orange" - the 2nd contact on the double-row 40-pin male connector







For the device connection, a putty terminal was used, which is also available under Linux, and, unlike minicom, it has a color output and does not require additional settings for entering characters into the terminal from the keyboard.



In general, the fee 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 normally works in multiplayer mode







A broken HDMI connector and the absence of an Ethernet interface is thus related to the configuration of the distribution itself. These problems, of course, will be solved and this is not about them. Therefore, we move on to the next item of the program.



5. PCB layout





Made it in Altium Disigner. The layout of the board is best done after the components are purchased. Perhaps, as in my case, you will need to install additional component libraries for Altium. The dimensions of the components and the topology of the footprint for each must correspond to the actual parts available. Here about me was not without annoying oversight, but more on that below.



I will say right away - do not use automatic wiring. Perhaps this is customizable, but the wiring system tried to push the track between the legs of the capacitors, which at a distance of 2 mm between them makes a track about a quarter of a millimeter wide, which for me as a “teapot” was too cool. Yes, and intuition suggested that such things should be avoided. Therefore, I used manual wiring (based on the results of automatic), setting the width of 0.5 mm in the rules of wiring (Design -> Rules -> Routing -> Width)







In addition, by default, Altium assumes that the board is dual-layer. In order to force it to plant a one-sided board, in the rules of wiring, you should specify the wiring in one layer, say in Top Layer







The schema was typed in the schema editor.







In this case, it is necessary to take into account the fact that the free non-soldered chip inputs (legs 8 and 10) should be pulled up to the ground, otherwise Altium will not compile the circuit for transferring it to the board editor.



As a result, by means of independent picking in the program and lessons of Alexey Sabunin the goal was achieved and the board was divorced







All components with mounting to the holes are located on the clean side of the PCB, and the microcircuit, due to the SMD performance, is located on the track side. To output the layout of the circuit to print, you need to create in the device project the so-called Output Job File







which is configured as follows. In the list of configuration options, select Documentation Output and click on Add New Docimentation Outpu, choosing PCB Prints from the pop-up menu and the design of the board for our device.







We rename the appeared item of the documentation, let's call it, say, LUT, on the transliteration of technology (LUT), which we are going to use to translate the circuit board image to copper. Right-click on the LUT and select Configure in the context menu. In the settings of the layers to be printed, we leave only two points: Top Layer and Multi-layer and arrange the daws as shown in the screenshot







Daw Mirror is needed in particular for the mirror image of the print. This is important, otherwise, when transferring the picture to copper, we get a mirror image of our tracks, but we don’t need it. You should also look at Page Setup.







to select a 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 should be equal to one.







Now click Print. I do not have my own printer, so I printed it in PDF using Foxit Reader, and then I took the resulting file on a flash drive to the closest “sharashka” to me, in which I printed the drawing on glossy photo paper. The result was this.







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



6. PCB manufacturing





The LUT method was chosen (laser-iron technology) because of its simplicity and accessibility. This article served as a guide to action on Habré . I tried not to violate the technology: I walked around the copper with zero, degreased, though not with acetone, because I did not find where to buy it, but with a universal degreaser based on white spirit, purchased from Lerua Merlin. Carefully and effortlessly ironed a textolite sandwich and drawing with an uyug at the maximum temperature. Either because I made a mistake somewhere, or because I didn’t allow the blank to cool, or just save the toner on the printer in a sharashka, in general, it’s not very







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







Next, a solution of 6 aqueous ferric chloride was dissolved at a rate of about 180 grams per 300 ml of water (water collected from the tap, hot) and the board was thrown into the cuvette for etching. To pickle the board and not poison my wife, the operation was performed at sunset on the balcony







"Hlonyak" did not disappoint, rumors circulate that they often sell low-quality ones. Etching took 13 minutes, the last islands of copper went right before our eyes. The main thing is not to forget to periodically kick the board with tweezers on the cuvette and follow the process. As soon as the excess copper disappears, we immediately get a fee and rinse with abundant water flow.



After washing, rubbing and drying, the moment of truth comes. It is necessary to remove the protective coating. I tried to do it with white spirit







but it was going tight. Then the wife offered her nail polish remover - this miracle elixir washed off the coating instantly (I am still terrified of the reagents our women use. Beauty is a terrible power!)



Not failed and the marker - all the tracks survived







After cleaning the protective coating, you can start drilling holes. And here I made an annoying mistake - I didn’t have a drill of 0.5 mm, and instead of postponing the case until tomorrow, having bought the necessary drill, I hurried up and took a millimeter, finding it suitable. As a result, I damaged many pads, fortunately not much and not irrevocably. But never hurry. As my friend Mark said from the laboratory of the mechatronics department at the University of Munich, where I was doing my undergraduate practice, “Dmitry, take the right tool for each job”. And he was right a thousand times.



7. Tinning of the board and soldering components





The solder joints should be covered with a thin, shiny solder layer. This is the main condition for successful work. I did not trick the track entirely. Firstly, I was afraid to bite them, and secondly I was still going to cover the board with a varnish. So I’ve only been able to solder places. To do this, we apply a rosin-alcohol flux LTI-120 and a soldering iron heated to 250-300 degrees with a brush, and a tiny droplet of solder hangs from the tip of the solder. By increasing the surface tension with the flux, the solder spreads to exactly the contact pads.



After that, the “mock-up” was disassembled, the wiring was removed from the microcircuit and it was soldered in the first place. Gently place the microcircuit in place with the hands or tweezers in accordance with the footing, so that each leg takes its place. Then we grease the rows of legs with flux. With short and precise movements, we touch all the legs in turn, not forgetting to take solder on the soldering iron tip (but not too much, just a small drop). If everything is done correctly, then the legs are soldered to the playground very quickly and accurately, without “snot” and overlapping the neighbors. It took me less than a minute to seal the microcircuit, and I do it for the first time. This video inspired me for this feat, 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 trim the conclusions of the parts to the desired length - I left hanging up above the track no more than a millimeter of output, and correctly and gently bend them if required. It is important, it is extremely important not to rush anywhere and do everything thoughtfully. The result is what happened







It was not possible to get away from the “snot”, but for the first time it came out pretty well, although I’m likely to be criticized.



8. Checking the chains and another annoying error





After soldering, flush the entire flux with alcohol, take a multimeter in our hands and call all the circuits in order to check their conductivity and conformity with the concept. And here byaka crept unnoticed. COM-port connector is soldered mirror! "Earth" sat on the first leg instead of the fifth, Rx - on the fourth instead of the second. And I still do not understand how, because everything was correct when distributing to Altium. It remains a mystery to me. No riddle - just having in fact a “mom” connector, in forming the circuit in Altium still used the “dad”. Hence the mirror pinout, resulting in a result. Fortunately, I solved this problem by appropriately unwinding the cable intended for connecting the device in the COM port of the computer. But because of this error, the COM on the board turned out to be so “proprietary”.



The rest of the installation turned out to be true, and I, having unsoldered the connecting cables and tidied up the workplace, connected the new board to the “orange” and the computer







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



9. Direct the "beauty"





In order to protect the contacts from oxidation and make the device look like an “industrial” board, it was painted with a green paint pad. All the marks put before the installation with a permanent marker were washed away with this very varnish. Well, okay ... Here is a photo of the finished product along with a set of cables







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



Conclusion





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



Thank you all for the attention paid to my writing!

Source: https://habr.com/ru/post/369467/



All Articles