Problems programming with externally powered target

USB AVR Programmer and SPI interface. Adafruit's USBtinyISP.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
ellrod
 
Posts: 9
Joined: Fri Feb 27, 2009 11:42 pm

Problems programming with externally powered target

Post by ellrod »

I am having some problems programming my ATmega168 arduino target board with USBtiny.

If I program with USBtiny JP3 removed and externally power my target board I am not able to program. I get this error:
USB read error expected 4, got -5
USB read error expected 4, got -5
avrdude: initalization failed, rc=-1
Double check connections and try again or use -F to override this check.

Since arduino is formatting the avrdude command I can't try -F to see if that would work.

If I connect and reconnect the programmer, pull it out of the PC and plug it back in, turn target power on and off, once in about 20 tries I can program the target.

If I install JP3 and disconnect target power, I am able to program the target board without problems.
I really don't want to do it this way since the programmer is then backdriving the on board voltage 5 volt regulator.

I don't understand why I can't program a target that is externally powered.

Anyone have any experience with this ?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: Problems programming with externally powered target

Post by Franklin97355 »

Make sure you have a ground between the programmer and target.

ellrod
 
Posts: 9
Joined: Fri Feb 27, 2009 11:42 pm

Re: Problems programming with externally powered target

Post by ellrod »

I assume you mean in addition to the ground already in the programming cable.

This is something I have not tried, I also have thought about the possibility of ground loop sensitivity.

I have three PCs that I have tried using for programming, one laptop and two desktops.

The laptop is the worst, on battery power or plugged into the wall I can't get that to work at all with external power on the target.
One desktop is similar to the laptop, but once in a while I can get it to program an externally powered target.
The other desktop is somewhat better, if I pull USBtiny out of the USB connector and then back in before each try I can usually get it to program, but never twice in a row.

I will look at adding a second ground lead from the programmer to the target.

Sure seems like the design is very marginal, I have built all sorts of USB controlled devices based on vendor controllers, it's hard to to make them not work. I'm really troubled by the zener diodes from ground to the data+ and data- lines. The data lines are high speed differential signals referenced to each other and need to be isolated from ground. When the zeners are present any ground noise or ground loop currents between the two endpoints is allowed to couple directly on to the the sensitive data lines. By design, a USB 2.0 compliant host is not allowed to drive the data lines higher than 3.6V anyway so the zener diodes are really unnecessary. The impedance matching resistors R1 and R2 provide a level of protection and isolation.

Just what is the purpose of the zeners and are they really necessary ? I'm very tempted to remove them and see if it will work properly, I have yet to see them on any Atmel design guide.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Problems programming with externally powered target

Post by adafruit »

you're confusing this with a native USB device. its not. its a USB bitbang, and the chip is running at 5V which requires reducing the voltage to ~3V using zeners. the design is 'non-standard' but works pretty well for a cheap programmer.
if you want a native USB programmer check out the AVR ISP or the AVR Dragon.

ellrod
 
Posts: 9
Joined: Fri Feb 27, 2009 11:42 pm

Re: Problems programming with externally powered target

Post by ellrod »

I understand how the bit bang part works but that is on the other side of the ATtiny, the USB side still has to act as a USB compliant end point, which enumerates and negotiates with the PC's OS to insure the proper USB driver is installed for the device and then get assigned a device ID.

Once that happens the PC still "talks" USB to the ATtiny and USB packets are exchanged to implement the bit bang. The packets are very small, just enough to exchange the 8 bit B-B data. So the voltage levels at the USB side still have to obey USB standards which is limited swing, 300mV to 800mV, depending on signalling rate. It can't be a 0-5V swing clamped to 3.6V. I have a digital scope here, I'll capture the swing and see what it is.

Please don't misunderstand me, I am not trying to be critical of the design, I think it is a very good one. I am just trying to get it to work reliably with an external power supply as advertised. I should be able to plug the programmer into a USB port and then plug the other end into a target and have it stay connected while I make changes to my code and run successive downloads. Instead I have to plug it in, attach it to the target, turn on target power, try to program but avrdude doesn't see the USB device any more so I have to pull USBtiny and replug it back in, try to program again and get USB errors. So I have to start over, turn off target power, unplug and replug USBtiny, and try and try again. On average it takes about 10-15 minutes of attempts before I finally get it to program my target.

The USB connection between the PC host and the ATtiny uP is getting dissrupted by the presence of power on the target. The most likely thing is ground loop current flowing through the USB cable which is upsetting the data connection. I just thought that noise may be coupling in to the differential data line from ground through the zener diodes. A good test that I plan to try is to power the target off a battery rather than an AC powered supply. That will eliminate any ground loops and it ought to work fine. I'll report what I find.

If you go back many months ago I posted a request for help on this same topic. I have been limping along since then and I have just really run out of patience. I decided to take a day to see if i can improve on the design and fix this so I can work more efficiently.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Problems programming with externally powered target

Post by adafruit »

are you using linux? what OS are you using? are you sure that you have good power on the target with a large enough capacitor? try powering the target first, be sure it has a nice 220uF cap or better on it. then you can program it with the usbtiny.
you can also try replacing the 12 mhz oscillator with a 12mhz crystal and 2 20pF caps. someone said that helped but it may be coincedence

ellrod
 
Posts: 9
Joined: Fri Feb 27, 2009 11:42 pm

Re: Problems programming with externally powered target

Post by ellrod »

I am using Windows XP, and my target board has adequate decoupling and bulk capacitance. Voltage level is stable and clean.
USB timing is forgiving enough to allow a good quality ceramic resonator to be used in place of a 12 MHz crystal.

As mentioned yesterday I tested the setup with the target powered by a battery and it worked much better, not perfect but better. If the problem was due mostly to ground loop currents I would have thought that this would have fixed it. It has to be that the signal integrity of the serial data stream is very marginal. I removed the zeners and retested and found perfect operation in all cases on all three of my PCs including the laptop which never worked. I can now plug the programmer into the PC, connect it to the target, power cycle the target off and on, disconnect/reconnect the programmer from the target multiple times, and never lose USB connection. I left the programmer connected to the target overnight and this morning I was able to program without any problem. The longest I could expect the programmer to work before removing the zeners would be 10 to 15 seconds before losing connection.

I also verified programmer powered programming and that works good too, no more USB disconnects in that mode either.

I will collect some waveforms today and send them in to show the effect of the diodes on the serial data waveform.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Problems programming with externally powered target

Post by adafruit »

great to hear you fixed it!

wlewis
 
Posts: 5
Joined: Sat Dec 12, 2009 8:34 pm

Re: Problems programming with externally powered target

Post by wlewis »

You call hooking up your board to a battery a solution? - I just want to make sure I understand.

Locked
Please be positive and constructive with your questions and comments.

Return to “USBtinyISP”