Can anyone confirm (and posibly suggest solutions) to my difficulty in programming ATMega328's at 3.3 volts. The ATMega328 will run quite happily at 3.3v, but when it comes to programming it is very unreliable – one in ten successes. A typical output is along the lines of:
:~> avrdude -c usbasp -p m328 -vv
(lines omitted)
avrdude: Device signature = 0x1e9514
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: safemode: Verify error - unable to read lfuse properly. Programmer may not be reliable.
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: lfuse changed! Was ff, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: hfuse changed! Was de, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: efuse changed! Was 5, and is now 0
Would you like this fuse to be changed back? [y/n] n
avrdude: safemode: Fuses OK (E:05, H:DE, L:FF)
avrdude done. Thank you.
Just some of the tests taken, include:
decoupling caps at pins 7/20 & 8/22
8MHz internal/external clock
multiple CPUs
multiple USBasp programmers
powering CPU from own supply & programmers 3.3v supply
scoping power and ISP lines suggest clean/square signals
It should be no problem at all to program it at 3.3V
Are you using the USBasp version 2 ?
Most common problems are : bad decoupling; a capacitor at the reset; cable too long; crystal not near the ATmega chip; bad or missing ground.
If you have already 100nF decoupling, try adding 100uF or 470uF to the 3.3V near the ATmega chip.
If you have only large capacitors (1uF to 1000uF), add 100nF to it.
I don't know what the problem could be, it can be so many things. With a scope a very small glitch can not be seen. Do you have other programmers ?
Perhaps the signals from the USBasp are 5V signals (I'm not sure, I think so), and your ATmeg328P is still running at 3.3V. Then you better use the 5V from the USBasp connecter to temporary run the ATmega328P at 5V.
Or get a programmer that will do 3.3V for sure, like my hex file loader from SD card, which can supply 3.3V power interface signals, or 5V power and interface signals: http://www.crossroadsfencing.com/BobuinoRev17/
Wait two weeks to get everything, then put it together let me know...
Well, I will have my parts before then and update the status... anyway like I said it is the worst option.
Wait two weeks to get everything, then put it together let me know...
Well, I will have my parts before then and update the status... anyway like I said it is the worst option.
Especially since the BOM doesn't list all the parts for that board, if they're even for the same board. I suspect U1 is rather important....
Thank you all for the very helpful suggestions and ideas.
As a courtesy, I thought I'd report back on my concluding findings before I move on to the next challenge!
As previously noted, I didn't like the ideas of mixed power supplies/level shifters. Anyway, as I understand it from (limited) reading of the datasheets, the ATMega328 (not sure about other AVRs), has no problem with “overdriving” the ISP pins – the ISP programmer will be using 5v while the target system is powered at 3.3v. The only qualification is that the ISP power connections (pin 2 of the 6 or 10 pin headers) are not made between ISP Programmer and target system.
So, that just left timings as a possible cause of my problems? I read that the the ISP SCK signel should be less that 25% of the target clock. Therefore as my 3.3v ATMega328 is running at 8MHz, I should be looking at a SCK of less that 500KHz.
Hooking up an Arduino as ISP (which has worked faultlessly during testing), I measure 125KHz - well within spec.
Next the troublesome cheepie eBay USBasp's, I see that they are running at 375KHz. This should be okay- maybe? Now, as we know, these boards have a “Slow Clock” jumper (JP3). Setting this and retesting, I note an SCK of 7.5KHz – Slow Indeed!
However, in the few days that I have been running my USBasp's with the slow clock enabled, they have worked flawlessly.
Job done, to my satisfaction, anyway!
Now the reasons for all the above are beyond me, but I am now content to be ultra cautious and run my USBasp's at 7.5KHz. I have seen references to an Avrdude “-B bitclock”, but I have not been able to get this to work for me?
Thanks for your report
I use USBasp with 16MHz and 8MHz (external and internal clock) ATmega chips without problem at normal speed.
In the past I had to change the clock for ATtiny chips sometimes.
I think it is a combination of your hardware setup (5V <-> 3.3V conflict; perhaps bad quality USBasp; perhaps the USB power is weak; perhaps a cable is not good; perhaps something is not good decoupled; and perhaps 10 more reasons).