Electronic – USB to TTL (CH340G) and maybe Logic level converter to program chips

digital-logicmicrocontrolleruart

Since i have a bunch of Atmega328p-pu(5v), Attiny85(1-5v), ESP8266(3.3v) & Raspberry's(3.3v) it was time to get:

  1. A USB to TTL
  2. Logic level converter

Now before buying that stuff i read about those USB to TTL converters.There are alot of them. Some need special drivers, some destroy chips if not original and some cost alot.

I found that one CH340G, i read good things about that USB to TTL. People are happy with the product and so i buyed it.

Like i said i need it both for the Atmel chips but also for the ESP8266 wich is 3.3v. It works on the ESP8266 with a minor problem. Some sources say that it needs drivers for older win OS's or OSX. I'm on win8.1 and it works out of the box apparently, even if i tried to install & uninstall the special drivers.

First Problem:

I can't get it to work with Atmega328-p pu. I only get "device not wroking correctly unrecognized".No COM port is listed in the arduino ide.
As the device CH340G only has TX RX 5v(also3.3v) & GND and NO DTR & RESET i gueess i need to put the (Atmel)chip in some sort of connection mode & pullup/down something. What?

Second Problem:

Like i said it works with the ESP8266. But i got a little suspicious after various transmission errors and measuring the TX & RX. In fact the voltage was 3.65v and dropped right after a sec to 3.58v. Now the Datasheet of the ESP8266 says it's limit is 3.6v and so i tried both of my logic level converter (One based on the PCA9306, one on mosfets). They both don't work. Device unrecognized. Is 3.65v ok if the max should be 3.6v? if not why do those logic level translator not work?

note:To test the logic level converter i used a AMS11117 3.3v regulator on the ESP8266 side and set the CH340G to 5v. basically if you want 3v logic you bridge the 3.3v pin if you want 5v you bridge the 5v pin to the VCC PIN.

Extra info:

Actually i got the logic level converters only to control a WS2812B Adressable led strip(5v) from a raspberry(3.3v). I read that those self made mosfet/transistor Logic level converters don't work properly. I also tried with some BSS138 mosfets(one of the first sparkfun's logic level converter), no luck. And so i got "expensive" ones. One is based on the PCA9306. I just noticed now that the second one is also just an array of mosfets. So basically the only "good" logic level converter is the PCA9306. i don't get why it does not work with USB2TTL.

EDIT related to questions in the comment.

The 328p-pu chips have an optiboot.. the default one (Arduino IDE). And yes i would like to program them on a breadboard. Thats why i got myself a usbtottl. It's frustrating to remove the chip everytime you have to upload something new.

Atm i'm using 2 original arduino UNO to program attiny's and atmega328p-pu.. but like i mentioned above its alot of work to remove the chip every 2 seconds.

To program the Attiny85 i made my own "shield" with the relative capacitor.
and connections to the UNO board.Also a simple blinky led to see if the bootloader is programmed correctly the first time.. or if i change the frequency.But that uses different pins.. not tx rx.

EDIT2

Solved second problem

It works on the ESP8266 with a minor problem.

To test the logic level converter i used a AMS11117 3.3v
regulator on the ESP8266 side and set the CH340G to 5v.

I added an additional external powersupply only for the ESP8266. Always using the AMS11117. but this time powered by a normal phone charger powersupply.
Looks like when programming it needs alot of power.There are no more transmission errors. So i guess this 0.05 overvoltage has nothing to do. And should not harm the mcu.

the main problem remains unsolved.

Best Answer

For your first problem, whether or not your ATMega328p is attached to the USB to TTL serial converter is irrelevant; if it is showing up in Device Manager, then the computer-to-converter connection is functioning properly. Every serial device should also show up in the Arduino IDE. Since it is not showing up in the Arduino IDE, I'd check Device Manager first; if it's not there, then you most likely have a faulty USB-to-TTL-Serial converter. Those CH340G board are really cheap and -- well, let's just say, you get what you pay for.

Note: I've seen at least one version of the board that has a jumper on it that lets you drive the I/O voltage with either 5V or 3.3V, which is super handy. If you forget the jumper, it ends up not powering the CH340G at all, which would cause Windows/Arduino to not detect it. Here's a picture of the CH340G board I've seen the jumper on before: CH340G, with selectable I/O voltage jumper

Now, once you get the device detected in Device Manager, it should be detected in Arduino's IDE as well; if not, restart the Arduino IDE. Once it's detected, you should be able to program your ATMega328p with the USB-serial board with one very important caveat: you must pull the reset line low right when you program the chip to manually reset into the bootloader. This is because your board does not have the DTR/RTS signals which Arduino Uno uses to pull the reset line low.

If that doesn't work, check to make sure you actually know what you're doing, with respect to breadboard connections. The ATMega328 is a pretty crappy MCU; you need an external crystal, decoupling capacitors, and a pull-up on the reset pin just to get it doing stuff (though it does have a slower, inaccurate 8 MHz oscillator, but without modifying the bootloader, you won't be able to use it).

Second problem: I assume your USB-to-serial converter is operating at 5V I/O levels; when you drive a 5V signal into a 3.3V MCU like the ESP8266, the protection diodes kick in, and limit the signal to about 3.6V or so (depending on the forward voltage of the protection diodes). You should never directly-drive 5V signals into a 3.3V part (even if it says it is 5V tolerant). I would run the TX signal through a 1k resistor into the ESP8266's RX pin. This will make it "easier" for the protection diode to clip the signal. Or, you know, you could just get a 3.3V USB-to-serial converter. I keep a stack of both laying around.