Adding TX and RX LED to CH340G - Page 1
Forum section: electronics / projects

author: siconic
author_rank: Contributor
timestamp: December 28, 2017, 01:13:48 pm
content: Hey guys!I am still working on a few modifications to my AIO programmer, and I want to add LED to the Power, TX and RX. I have seen them wired every which way from Sunday, so I am a bit lost as to why you would wire one way over another, and when.So for power I get the following, with no resistor, since I should be able to get a red 3.3V 0603 LED:For TX and RX I want to use Blue 0603 LED`s. But I have seen them wired to 5V, 3.3V, and GND. So on this part, 2 questions:1. How would I hook them up and why??? Is there more than 1 way to go about it? I have seen a 2 resistor setup, one on the 3.3v side, and one on the RXD/TXD side; I have seen RXD to GND, with resistor on GND, etc.2. This is a noob question, but how do I value the resistor for the LED`s, and do they always need one?Here is what I envision, the 2.2k resistor is a placeholder:

author: siconic
author_rank: Contributor
timestamp: December 28, 2017, 02:47:22 pm
content: Well, I certainly found an answer that helps me understand better. It appears to be less about voltage, and more about current.https://electronics.stackexchange.com/questions/27561/why-we-use-330-ohm-resistor-to-connect-a-ledHowever, I still am unsure of how to proceed with making the LED's react to a signal from the TX or RX of the CH340.

author: Peabody
author_rank: Super Contributor
timestamp: December 28, 2017, 05:19:13 pm
content: TX and RX should be high when no transmissions are taking place, and I assume you would want the LEDs to be off in that condition. If so, that means you want them to light up when TX or RX goes low - the Start bit and all low data or parity bits during active transmission. That setup would be:3.3V ---> resistor ---> LED ---> TX/RXYou would need to pick the resistor and LED color such that the brightness is enough to see readily, and the current consumption is acceptable. But generally, less current is better than more current, and you'll be surprised at how little light you really need. At some point, the more current will affect the maximum transmission speed.For the power LED, you're going to need a resistor even if you use a blue LED:3.3V ---> resistor ---> LED ---> GNDAn alternative for a power indicator is to put the LED on the DTR output of the CH340. DTR should be high all the time unless some handshaking is going on, so in effect DTR tells you the power is on, but also gives you an indicator of handshaking, which can be useful for troubleshooting.DTR ---> resistor ---> LED ---> GNDI guess in theory you could connect these to 5V instead of 3.3V so long as the voltage drop of the LED is greater than 1.7V. But I don't see any advantage to doing that. Maybe someone else will comment on that.I would suggest you look further into color selection, and see which LED color and resistance combo gives you the most bang for your milliamp.By the way, there are CH340 modules available on Ebay for less than $2 that have all these LEDs. I'll see if I can find one in my junque box. But it might be interesting to trace out how the module LEDs are connected - as something to compare to.

author: siconic
author_rank: Contributor
timestamp: December 28, 2017, 06:07:58 pm
content: Quote from: Peabody on December 28, 2017, 05:19:13 pmThats what got me started on this! I bought 2 of them from Fleabay for $1.50 each, but they are garbage... So I wanted to design my own, so I did not need an external FTDI.Is the DTR voltage and TX/RX all 3.3V high? If they are, and an LED is 3.3V, would I still need a resistor? And if so, how do I choose a resistor value?

author: Monkeh
author_rank: Super Contributor
timestamp: December 28, 2017, 06:27:13 pm
content: You want to design your own based on the crappy CH340 so you don't need to use a better chip?

author: rhb
author_rank: Super Contributor
timestamp: December 28, 2017, 06:39:34 pm
content: Long ago, in another time, I made an RS-232 cable which was switchable between straight thru and crossover (aka null modem in the day). I used bicolor LEDs wired up so I could connect it and flip a switch so both LEDs were green to make the proper connection. Thhe switch simply swapped the Rx & Tx connections.In your case, you want to wire them so when the line is idle the LED is off. That way they will blink when there is traffic. I'll let you sort out what that is. I don't remember, so better not to say. It should not be difficult to figure out.Consider your use cases. You might want to want to show both idle and active as I did. You also might want to consider making it selectable for 3.3 or 5 V signal levels. IIRC a lot of old gear used 12 V signal levels. I suggest reading the RS-232 docs.

author: phil from seattle
author_rank: Super Contributor
timestamp: December 28, 2017, 06:44:01 pm
content: Yes, you need a resistor to limit the current. Do you absolutely need blue? Personally, I'd use LEDs that have a typical Vf lower than 3.3.There is a lot of variability in the Vf of an LED. The datasheet will show a range of Vfs, you will get parts somewhere between Vf min and Vf max. Also, Vf increases with forward current so if you keep the current low, you may be ok. You can get by with pretty low current since you don't need much illumination. See the datasheet - it should have a graph of If vs Vf.I would test any LED you plan to use. See how low you can go with the current and still get reasonable light out of it. Then measure the Vf across the LED. Plan for variability of the final part you put on the PCB if you can't reuse the test part. (you could mount it and test in place)

author: phil from seattle
author_rank: Super Contributor
timestamp: December 28, 2017, 06:49:44 pm
content: Quote from: Monkeh on December 28, 2017, 06:27:13 pmWhat chips would you suggest? The CH340 works pretty well, is simple to use and is super cheap. The various FT232s cost more than many microcontrollers.

author: Peabody
author_rank: Super Contributor
timestamp: December 28, 2017, 06:50:43 pm
content: I found a CH340 module, but I was wrong about the LEDs. It only has a power LED. But I also found a CP2102 module and an FTDI module, and both have power, TX and RX LEDs, wired as I described above. All the LEDs are red, and the resistors are 1K. They are brighter than they need to be, and I suspect 2.2K would work fine.3.3V ---> resistor ---> LED ---> TX/RX3.3V ---> resistor ---> LED ---> GNDIf the LED really has a forward voltage of 3.3V, and you connect that to the regulated 3.3V supply, then it will never light up because the voltage differential across the LED isn't higher than its forward voltage drop, hence no current will flow. But more likely the forward voltage will be some value between 3.1V and 3.3V, which will vary with the current. But if it's really 3.1V, then with no resistor large amounts of current will flow. The voltage regulator will do everything it can to maintain the voltage at 3.3V, but the the LED will shunt everything above 3.1V. In a short time, all the magic smoke will escape from either the CH340 or the LED, and as you know, electronic parts will not operate if their smoke has escaped. I think using blue LEDs in a 3.3V circuit will just complicate your life. But that's just my opinion.You always need to use a resistor with an LED. You'll sometimes see people drive an LED from an Arduino I/O pin without a resistor, but that only works because that I/O pin will only source a limited amount of current in the first place. But even then, it's just not good practice, and a bad habit to get into.

author: phil from seattle
author_rank: Super Contributor
timestamp: December 28, 2017, 06:56:35 pm
content: Actually, the Vf numbers are not absolute. As I pointed out above, they vary with If and manufacturing/process variations. An LED that is fed a very low If will have a lower Vf and could well work in your system. You can experiment with this if you have a variable power supply. The point where the LED stops emitting is often quite a bit lower than the listed typical Vf.

author: siconic
author_rank: Contributor
timestamp: December 28, 2017, 07:00:22 pm
content: Quote from: Monkeh on December 28, 2017, 06:27:13 pmWell, I was thinking of using better chips, like the CP210* or the FT232, but I can get the CH340 for $0.40 each, vs $2.50 and $4.50 respectively, not to mention that the drivers for the CH340 are readily available. When i said it was crappy, what I meant was that the chinese designed and made ESP-01 programmer with the CH340 on it, was ultra crappy. Need to add your own push button to program it.

author: Peabody
author_rank: Super Contributor
timestamp: December 28, 2017, 07:04:51 pm
content: I've had good luck with the Silabs CP2102, which doesn't need a crystal. But it's only available in QFN, which makes it very difficult to use in prototyping. So that means you'd probably need to use a module. I've have had good luck with this one:http://www.ebay.com/itm/162217753561but it doesn't bring out all the I/O pins to the pin header. It has DTR, but not RTS. So you would need to see which lines are actually needed in your application. One other disadvantage to this module in particular - some of them output 4.3V on the outputs instead of 3.3V, which could destroy a 3.3V processor. The ones I got from the above link were fine, but that's been a while, so you would have to measure the voltage before actually using it. (The fix for the 4.3V is to cut the trace going to pin 9 of the CP2102, which should have been left floating. Then it will be 3.3V)

author: Monkeh
author_rank: Super Contributor
timestamp: December 28, 2017, 07:13:27 pm
content: Quote from: siconic on December 28, 2017, 07:00:22 pm$0.40 + crystal + large package + dealing with no usable datasheet + no signed drivers vs $1.33 with no crystal, convenient package, a proper datasheet, and signed drivers. Yep, CP2102's a fail..

author: phil from seattle
author_rank: Super Contributor
timestamp: December 28, 2017, 07:20:49 pm
content: Quote from: Peabody on December 28, 2017, 07:04:51 pmQFNs are pretty easy to hand solder. You can use QFN breakout boards which aren't too expensive. (Or use cheap Chinese PCB vendors to make a proto board). I've even used deadbug style soldering something like 28 ga wire to the pads - UGLY but effective.

author: siconic
author_rank: Contributor
timestamp: December 28, 2017, 07:38:37 pm
content: Quote from: Monkeh on December 28, 2017, 07:13:27 pmYou bring up a valid point, but I don`t think there is any need to be snarky. As a noob I am bound to make bad choices, and I do intend on making my next iteration from the CP2102 anyway.I do like it a little better, for all the reasons you mentioned. But I happen to have all the stuff for the base prototype in CH340. I also do not have a heat gun for a QFN, but plan on getting one soon. Also, I found the datasheet and pinout much quicker for the CH340, so not sure what you mean no datasheet. I have been using arrow, and should have checked DigiKey, they are in stock and $1.40 like you said.

author: phil from seattle
author_rank: Super Contributor
timestamp: December 28, 2017, 08:08:09 pm
content: Here's an example of using the 2102 QFN deadbug styleWeb sitehttp://www.kerrywong.com/2010/07/16/an-arduino-compatible-using-cp2102/

author: siconic
author_rank: Contributor
timestamp: December 28, 2017, 09:42:30 pm
content: Quote from: phil from seattle on December 28, 2017, 08:08:09 pmLOVE IT! I always wondered how you would prototype using SMD parts, and now I know.

author: phil from seattle
author_rank: Super Contributor
timestamp: December 28, 2017, 10:12:43 pm
content: Quote from: siconic on December 28, 2017, 09:42:30 pmI'd recommend using a breakout board. They are cheap. an example -https://www.ebay.com/itm/2PCS-QFN24-0-65mm-0-5mm-to-2-54mm-DIP-Adapter-PCB-Board-Converter-IC-test-F24/171934670480?hash=item28081ade90:g:KasAAOSwZuRZz635shipping via china post takes 2 to 3 weeks.Too bad you missed out on the AllPCB free shipping offer. 10 PCBs delivered to your door for $5.49 in less than a week. (it's up to $20 now, I hear) I made a number of breakout boards that cost less than the ones I linked to and received them in about 1/3 the time. You could still use OSHPark - small boards don't cost that much.

author: Peabody
author_rank: Super Contributor
timestamp: December 28, 2017, 11:45:38 pm
content: siconic, can I ask you about the larger circuit? I went back and read your original thread on your programmer, and am a little confused about the power supply situation. It looks like you have a voltage regulator that produces the 3.3V rail from the USB 5V supply. Does that provide 3.3V to both the CH340 and the wireless module?I ask because I wonder if the CH340 doesn't have such a regulator built in. The CP2102 does, and it might allow you to eliminate the separate voltage regulator. The CP2102 regulator is rated for 100 ma. If you were going to redo the PCBs to add the LEDs and resistors, you might consider changing over to the CP2102 or CP2102N. Of course you would have to deal with soldering or heat-gunning the QFN-28, and that could be a problem. Or, you could mount a CP2102 module on your board, complete with LEDs, so all you would need to add is your push-button switches.Well, just a thought.

author: siconic
author_rank: Contributor
timestamp: December 29, 2017, 03:05:38 am
content: Quote from: Peabody on December 28, 2017, 11:45:38 pmI do have a seperate voltage regulator, originally for 1, but now for 2 reasons:1. I needed to power the ESP-01, and I figured its better to use the larger regulator, so you can use the pinouts for additional devices, and should provide plenty of power for most testing.2. Once I read above about how the CP2102 can sometimes run higher than 3.3v, I figured I would just go ahead and keep it in. Cant go wrong with guaranteed 3.3V, clean power.Let me know if I am just as safe with a smaller regulator, or none at all. I chose this one for cost. A little big, but cheap.Sent from my SM-G950U using Tapatalk

author: cdev
author_rank: Super Contributor
timestamp: December 29, 2017, 03:14:48 am
content: I have a cp-2102 module that breaks out all the data lines. It also has a TxD and RxD LED.Its currently doing duty on one of my GPS's but I can turn it off and take a photo. I had to solder a header on for the extra lines but that was easy as the lines were already there. I know they work because I often use them and I will put LEDs in series with a resistor to tell me what the state is.Similarly I have a Ch-341 dongle that breaks them all out too.Its kind of a super USB-UART dongle that also supports SPI and i2c and parport emulation and has a 3.3 or 5 volt regulator too I think.A few years ago everybody was dissing the CH340 but Ive found my (several) CH340 devices to work reliably.I'm on Linux and there is a good driver for it, no extra drivers are necessary.Note, although I have the code to do so I have not tried out the SPI or i2c functionality of the CH-341 device yet.FTDI has a similar i2c/SPI capable device now and Adafruit sells a breakout board with it on it for around $10-$12 so because of her making a library for the FTDI device that may be a better choice if you want that. But for USB-UART the CP-2102 is really reliable. It always works for me. I use it a lot.

author: Peabody
author_rank: Super Contributor
timestamp: December 29, 2017, 03:50:52 am
content: Quote from: siconic on December 29, 2017, 03:05:38 amI found some info on the ESP-01, and it says it requires 70ma for normal operation, and 300ma maximum. I don't think the regulator in the CP2102 would be reliable for that, even at the normal current. So the seperate regulator is the way to go. But if it was me, I'd still go with red or green LEDs and 2.2K resistors.I need to clarify things concerning the CP2102s ouputting voltage above 3.3V. There's nothing wrong with the chip itself. It's just that one version of the module PCB has a trace going from the USB 5V supply to pin 9 of the chip, and that's what's wrong. If you get a module that doesn't have that trace, so that pin 9 just floats, there won't ever be any excess voltage. I'll attach a pic of a good one. Unfortunately, Banggood was a source of bad modules, and I don't know if that's been corrected now. But the Ebay seller I linked to above sent me good modules.Basically, the chip has an internal ESD protection diode going from pin 9 to the 3.3V rail. Applying 5V to pin 9 causes the 3.3V rail to increase to one diode drop below 5V, or roughly 4.3V. And that makes the on-board 3.3V regulator shut down. It's just bad board layout, or possibly done deliberately to make the CP2102 more compatible with 5V Arduinos.

author: Peabody
author_rank: Super Contributor
timestamp: December 29, 2017, 04:04:36 am
content: Quote from: cdev on December 29, 2017, 03:14:48 amI use the CP2102 to flash firmware updates to my MSP430 parts via BSL, and to my cheap-ass $21 kit oscilloscope, and I've found it to work just fine. But I think that's probably true of all three brands now. I know that a lot of the pretend Arduinos use the CH340, and I believe the real ones use FTDI. I think all the chips probably work ok. Any issues are probably more related to module design or getting the right drivers not the chips themselves.I should also mention that in another thread a guy reported that he had found on Ali Express a CH340 version that doesn't require a crystal. I don't know if that's a genuine CH part or a knockoff, but that would be a nice upgrade for the CH340 - no crystal, and no caps for it.

author: phil from seattle
author_rank: Super Contributor
timestamp: December 29, 2017, 05:00:56 am
content: According to the datasheet, pin 9 on the QFN28 version (which is what your's looks like) is active low reset. Not sure I understand why that would cause the VReg to put out higher voltage. The datasheet says to pull it up to "Vio" for peripherals but in the case of none, tie it to Vdd.

author: Peabody
author_rank: Super Contributor
timestamp: December 29, 2017, 06:27:15 am
content: Quote from: phil from seattle on December 29, 2017, 05:00:56 amEither of those would be the 3.3V rail. But in the bad modules pin 9 is tied to 5V. There's an internal diode going from pin 9 to the 3.3V rail which is supposed to dissipate any static charge. 5V at pin 9 would go through the diode to the rail, which results in 4.3V there. The internal regulator can pump additional current to maintain 3.3V, but there's no mechanism to reduce the voltage if it's too high. So the regulator shuts down, and the voltage stays at 4.3V. In practice, pin 9 is usually left floating unless it's going to actually be used to reset the chip. It works fine that way.I have cut the trace going to pin 9 on a bad module, and the output voltage reverted to the correct 3.3V, and the module worked fine after that. So I'm pretty sure the explanation and fix are correct.

author: cdev
author_rank: Super Contributor
timestamp: December 29, 2017, 02:43:54 pm
content: You probably already know this because you want to use the USB-UART for power which makes it very convenient and also is likely to cause fewer problems with many small device setups than anything else..I find the CP-2102's power adequate for many small devices..But for the benefit of others reading - its always good to remember, if the other thing you are plugging into has its own power, make sure the common ground is solid, and then only use three wires.. TxD Rxd and that Gnd.Unless you are absolutely sure it wont cause problems- especially if one of the wires- like the ground is momentarily lost - if your ground is solid, that is quite helpful- Its also helpful if there is only one PS -don't have multiple power supplies feeding into something.. if you can use the same USB for power thats quite helpful. Alternatively, use separate supplies but have a strong common ground that wont accidentally come undone and then just use the UART lines for the signal and not powerOr you could conceivably fry your device or even your computer.

author: bson
author_rank: Unknown
timestamp: December 29, 2017, 08:36:21 pm
content: Quote from: Monkeh on December 28, 2017, 07:13:27 pmDon't forget it has an internal EEPROM, too. And the over-USB customization software actually exists. Not to mention the driver installer actually works (and doesn't have a Win3.1 look-and-feel) on Win10.

author: boffin
author_rank: Unknown
timestamp: December 29, 2017, 09:05:52 pm
content: Quote from: siconic on December 28, 2017, 01:13:48 pmSerial is active low, do there's data when it's at 0 volts and idles at 5v (or 0/3.3 or, -12 / +12 for real RS232), so you want the LED hooked from power to the pin, not from the pin to ground.VCC -> Resistor -> LED -> TXVCC -> Resistor -> LED -> RXVCC -> Resistor -> LED -> GND (power)You need to limit the current through the LED to a couple of mA (say 1.5mA), and as the LED will drop about 2V (a little more for blue), the resistor needs to drop the other 3vOhms law: R = V/I= 3/0.0015= 2k (probably anything from 1k to 3k3 would work just fine, I personally would use 2k2 because I like sticking to the 10/22/47 E3 series)EDIT: fix math

author: bson
author_rank: Unknown
timestamp: December 29, 2017, 09:22:01 pm
content: Uhm, but the CP2102 has separate TXT/RXT pins exactly to drive activity LEDs.OP: you want a resistor to control the LED brightness - some will be exceedingly bright at even 2-3mA. Put a pot in series and just see where you find a good brightness; dial it in then measure the pot and pick a close resistor value. LEDs that are too bright are just annoying, as are ones so dark they're barely visible. Each make and color of LED will need a different value. It's pointless to sink 20mA through a LED that's annoyingly bright, when 1mA is perfectly good. (I have ultra-bright 0603 LEDs bought off eBay that are at perfect indicator brightness at 0.3-0.5mA!)

author: gertux
author_rank: Contributor
timestamp: December 29, 2017, 10:44:42 pm
content: Quote from: Peabody on December 29, 2017, 04:04:36 amThat's correct models CH340B C and E don't use an external crystal. Never used one of those however.Sent from my iPad using Tapatalk

author: Peabody
author_rank: Super Contributor
timestamp: December 29, 2017, 11:15:14 pm
content: Quote from: cdev on December 29, 2017, 02:43:54 pmYes indeed. And it turns out that this issue of which power source should be used can be tricky. For example, if you power up the device being flashed from its own supply, and limit the USB adapter's connections to TX, RX and GND, you still have the issue of what voltage the device's Vcc is set to. if it's 3.3V or 3.6V, then that should be no problem. But if you're running a low-power MCU at 2V, then you're going to be feeding TX to it at 3.3V, because that's what the adapter outputs, and that may violate the MCU's absolute rating for voltage applied to any pin relative to Vcc, and smoke may escape.There can be a similar issue related to which device gets powered up first. If you power up the adapter via USB before you power up the device, then you're applying 3.3V from TXD to a processor whose Vcc is still at ground. Some processors are designed to deal with that well, but not all.So I would agree that in general it's less likely to cause problems if you can power the device from the adapter's regulated 3.3V output, and leave its normal supply switched off. Everything comes up at the same time, and the voltages are always right. But if you can't do that, then you need to think through exactly how this is going to happen, and check the datasheet for those absolute ratings for the device you're flashing.