26 Jun 2011
A friend of mine is working on his own custom Arduino powered LCD backpack and asked me to look at his design. I noticed it had a header for the all to familiar FTDI board to program the Arduino and a separate header for power and data connection. Both headers had the ATMega’s UART pins broken out. The problem with this design is it then requires the user to disconnect whatever they have connected to the second set of UART pins whenever they want to attach the FTDI board to upload a new sketch. With a few more passive parts, he could eliminate that need. This is a quick tutorial for beginners looking to roll their own Ardunio boards and may have missed this very easy and time saving design trick.
Let’s take a look at his effective schematic. I’ve only drawn the UART lines to keep things simple.
The problem here is if two different devices (like an FTDI and another Arduino) are both trying to drive the TXO line something will burn out or just not work. It would be like shorting 5V to GND, bad things will happen. So if a user wanted to reflash the onboard AVR chip with an FTDI, they would have to disconnect whatever was plugged into the other UART header.
But if you add one or two resistors you can avoid that. Let’s take a look at this design.
Ok, so now we have two 1k resistors seperating the second UART header from the AVR and FTDI header. But what are they doing?
Well, lets think about it. If the FTDI is plugged in and sending a logic 1 (or HIGH) while a second device is sending a 0 (or LOW) it will create a voltage drop across R1. If we are dealing with a 5V system, about 5mA will flow through R1 according to Ohm’s Law V=IR. 5mA is a safe low current for most devices to handle and the opposing devices won’t harm each other. But the ATMega will only ‘hear’ the device that is on the same side of the resistor.
Maybe a simulation (via Falstad) will make things a little clear. Here’s our new design. Let’s say RED represents a logic LOW and GREEN is logic HIGH. I am using two pulse generators to represent data being transmitted from 2 UARTs. Lets see what the ATMega sees when two devices are both trying to transmit at once.
So the resistor gives the FTDI chip ‘priority’ over whatever is connected to the second UART header. If there is no FTDI plugged in, the ATMega will ‘hear’ whatever is coming in on the second UART header. This is because the ATMega’s RX pin is effectivly a open circuit and draws no current. No current means no voltage drop across the resistor and the signal gets through unaffected.
This means you are safe to flash new sketches without unplugging anything. Well, safe data wise. There are concerns about the FTDI’s onboard power VCC pin fighting with whatever power supply may be running on your widget, but that’s another tutorial.
This trick is how the regular Arduino board allows you to access with ATMega’s UART pins without fighting the onboard FTDI chip. Let’s take a look at it’s schematic:
There you see the ‘prioritizing’ resistors on the UART lines between the FTDI (or it’s replacement) and the main ATMega. This mean if anything is plugged into the UART pins (digital pins 0 and 1) it will ‘override’ whatever the FTDI is transmitting.
So there you have it. Two resistors in your design can make it easier and safer to upload new code.
If you found this post interesting or helpful, please consider sending in a donation or disabling any ad-block plugin on my site. Proceeds go to my various education outreach efforts, towards repairing museum exhibits, or to my beer fund.