ISP Programming ATMega328 at 3.3v

Hi,

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: 1. decoupling caps at pins 7/20 & 8/22 2. 8MHz internal/external clock 3. multiple CPUs 4. multiple USBasp programmers 5. powering CPU from own supply & programmers 3.3v supply 6. scoping power and ISP lines suggest clean/square signals 7. reposining on breadboard to reduce crosstalk 8. scouring the Internet for similar comments...

Best regards, Martin

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.

Koepel: Are you using the USBasp version 2 ?

No. I'm not sure! How can I check? The board silkscreen says "USBASP V2.0 - LC Technology" for what that's worth. And lsusb -v shows:

:~> lsusb -d 16c0:05dc -v

Bus 001 Device 028: ID 16c0:05dc Van Ooijen Technische Informatica shared ID for use with libusb
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x16c0 Van Ooijen Technische Informatica
  idProduct          0x05dc shared ID for use with libusb
  bcdDevice            1.04
  iManufacturer           1 www.fischl.de
  iProduct                2 USBasp
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           18
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower               50mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         0 (Defined at Interface level)
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
Device Status:     0x0000
  (Bus Powered)
:~>

Does that tell me anything?

Regards, Martin

USBASP V2.0 means Version 2.0

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.

Thanks for the suggestions though. It gave me something to try

USBASP V2.0 means Version 2.0

Just to check, I dumped the firmware from my programmer and did a dhex against usbasp.atmega8.2011-05-28.hex from http://www.fischl.de/usbasp/ and it is a match. So I guess that it is version 2.0.

Do you have other programmers ?

Yes, but they are both “budget” USBasp from China

Perhaps the signals from the USBasp are 5V signals

Yep. Thats what I'm scoping.

Then you better use the 5V from the USBasp connecter to temporary run the ATmega328P at 5V.

Hmmm Possible. But the risk of not isolating the 3.3v bluetooth modules is too high for me to risk it!!

I guess I'm just going to have to put my hands in my pocket and replace my Olimex?

Either run the chip at 5v to program it, or install the ArduinoAsISP sketch on a 3.3v arduino, and use that as ISP programmer.

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/ |500x488

Now for the worst option of all time...

Buy this level convert board from OSHpark

https://oshpark.com/shared_projects/1at0dYOR

Order the parts on this BOM (Digikey)

http://epccs.org/indexes/Board/ICSP/Design/15321,BOM.csv

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.

ron_sutherland: Now for the worst option of all time...

Buy this level convert board from OSHpark

https://oshpark.com/shared_projects/1at0dYOR

Order the parts on this BOM (Digikey)

http://epccs.org/indexes/Board/ICSP/Design/15321,BOM.csv

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....

Ha... good catch give me a few to fix it.

I think it is fixed now. This is the schematic for that board also, and I will fix errors on it as well.

|500x375

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?

Regards, Martin

Thanks for your report :slight_smile:
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).