Problem using USBtinyISP to program ATMEGA328P

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
User avatar
indy
 
Posts: 21
Joined: Tue Dec 04, 2012 1:30 am

Problem using USBtinyISP to program ATMEGA328P

Post by indy »

Hello,

I'm using a Arduino compiled hex file, avrdude and USBtinyISP to program an ATMEGA328P chip.

Just doing the basic hex load using the command below works:

Code: Select all

avrdude -c usbtiny -p m328p -b 57600 -U flash:w:sevenseg.cpp.hex:i
The program runs about 16 times slower than on an Arduino (this makes sense since default chip config is 1MHz vs Arduino 16MHz).


My next step was to clear CKDIV8 fuse and this also works:

Code: Select all

avrdude -c usbtiny -p m328p -b 57600 -U flash:w:sevenseg.cpp.hex:i -U lfuse:w:0xe2:m
Now the program runs 2 times slower than on an Arduino (this also makes sense it is now at 8Mhz vs Arduino 16MHz).


My next step was to add an external crystal (and supporting capacitors) to the circuit and set the appropriate fuses:

Code: Select all

avrdude -c usbtiny -p m328p -b 57600 -U flash:w:sevenseg.cpp.hex:i -U lfuse:w:0xff:m
This is where everything fails. The program no longer runs and I no longer can get any response from the USBtinyISP:

Code: Select all

avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.
I've checked (and re-checked) the crystal/capacitors connections many, many times and don't see a problem (it's a simple connection).

Any ideas or suggestions to what I can try? Thanks for your help.

User avatar
indy
 
Posts: 21
Joined: Tue Dec 04, 2012 1:30 am

Re: Problem using USBtinyISP to program ATMEGA328P

Post by indy »

Update: I was able to hook up an Arduino to simulate a clock and get the chip's fuses reset to use the internal clock. So now it is back to working in the 8Mhz mode (internal clock, no divide by 8) and of course I can communicate with it.

So something seems to be wrong with my external clock setup. I used the following crystal and capacitors:
http://shop.evilmadscientist.com/produc ... 44-xtlcaps

I connected one leg of crystal to XTL1 and the other to XTL2. One capacitor from each leg of crystal to ground. Anything sound incorrect there?

Or was it my fuse configuration? low fuse = 0xFF

Thanks,

User avatar
indy
 
Posts: 21
Joined: Tue Dec 04, 2012 1:30 am

Re: Problem using USBtinyISP to program ATMEGA328P

Post by indy »

Update #2: I found this thread:
http://forum.arduino.cc/index.php?topic=288843.0

Changing the fuse from 0xFF to 0xF7 didn't work but removing the capacitors completely did work. I now have it running at a full 16Mhz (same speed as Arduino).

I guess now I need to do more research on this crystal / capacitor issue...

Thanks,

User avatar
nsayer
 
Posts: 59
Joined: Thu Aug 08, 2013 10:45 am

Re: Problem using USBtinyISP to program ATMEGA328P

Post by nsayer »

0xF7 is almost certainly the wrong value. http://www.engbedded.com/fusecalc/ describes that as a "full swing" crystal. What you want is a fuse setting of low=0xff. That's an 8+ Mhz external crystal oscillator with a kind of long-ish (relatively speaking) startup delay.

You probably want to pick a crystal with a load capacitance in the 18-22 pF range, and then use 22 pF load caps. But don't just blindly do that... Read this: http://www.adafruit.com/blog/2012/01/24 ... ur-design/

If you don't mind the 8 MHz internal oscillator, though, and just want your sketch to have proper timing, then just make your own boards.txt entry for an 8 Mhz internal oscillator ATMega328. If you pick that "board" from the boards menu, then your sketch will run at the "right speed."

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

Return to “USBtinyISP”