When I connect the Tx and Gnd of the programmer to my atmega328p, with the 328’s Vcc disconnected, the chip powers up and starts executing my code. For instance, if the code flashes LEDs in sequence, as soon as I plug in the programmer, everything starts working, but the LEDs are dimmer than usual.
I turned on Brown-Out Detection, and that seems to correct the behavior, but can someone explain why?
How is it that the chip and circuit can power up off of the tx line of the programmer?
I can recreate this 100% of the time.
Programmer’s Tx is connected to atmega’s Rx, and both devices are connected to a common gnd bus. Vcc is disconnected. Programmer is attached to laptop.
Ok, taking a shot in the dark here. Is this happening because of the I/O protection diodes? I just read in the datasheet that “[a]ll I/O pins have protection diodes to both Vcc and Ground as indicated in Figure 13-1.”
Figure 13-1 shows a diode going towards Vcc, and another going from Ground. Does this mean that when the chip is powered off, the current from the Tx on the programmer is flowing in pin PD0 (which is Rx), and flowing to my Vcc bus, thus activating the chip and powering the rest of the circuit? If so, when I enabled brown-out detection, did it stop the chip from turning on in this unintended scenario?
Am I doing anything that may damage the chip or the programmer, or worse, my USB port?
Thanks to anyone who may be able to shed some light on this.
Hello Louie. Your theory about what is happening is correct.
Enabling brown-out detection may prevent your AVR from executing code during this scenario, but it doesn’t change the fact that AVR and everything else connected to the AVR’s VCC node are being powered through the programmer’s TX line, which is not ideal.
Yes, what you are doing has the potential to damage any of those three components if you draw too much current from your AVR’s VCC line. I recommend that you power your AVR board from a separate source before connecting the programmer.
If that’s not convenient, you can alternatively power your AVR board off of USB. The programmer has a pin that allows you to access the +5 V USB power line. Connecting USB power to your AVR’s VCC line would be better than what you are doing now, but you still have to worry about drawing too much current and damaging your USB port.
Should I not be connecting the programmer’s Tx directly to the Atmega328? Should I perhaps have some kind of buffer or switch between the Tx of the programmer, and the Rx of the Atmega? If I were interfacing two devices with two separate power supplies, how could I be sure that turning one device on while the other was off wasn’t going to break either one?
Thanks again for the advice!
The easiest thing I can think of is to connect the TX pin of one device to the RX pin of another through a 220 Ohm resistor. Then at least you know that you won’t be drawing a large amount of current through that connection. You can also put a diode between the two pins to guarantee that current does not flow from the TX line of one device to the RX line of the other device (this will only work if both sides have pull-up resistors on their RX lines, which they should have in your case). You could probably think of something better using transistors though.
Also, I think you should apply power to your AVR board first, because the programmer is less likely to have something on it that draws a lot of current.