USBtiny with atmega328: How to hookup, and Avrdude 5.5

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

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by soerena »

Why is the atmega328p not mentioned on the list here: http://www.ladyada.net/learn/avr/avrdude.html ?
Does this mean the usbtiny can't program this chip?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by adafruit_support_rick »

soerena wrote:Can't I just upload a bootloader with the arduino uno and a new 328p chip ? no?
No. You need a programmer of some kind. See here: http://arduino.cc/en/Hacking/Bootloader ... Bootloader
soerena wrote:Can I upload arduino sketches to a 328p that doesn't have the bootloader, by using the usbtiny? And this way avoid spending flash memory on the bootloader.. ??
Yes! You only need to bootloader if you want to upload from the Arduino IDE.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by adafruit_support_rick »

soerena wrote:Why is the atmega328p not mentioned on the list here: http://www.ladyada.net/learn/avr/avrdude.html ?
Does this mean the usbtiny can't program this chip?
That's an old list. If you run the 'avrdude -c avrisp' command on your machine, you'll see this:

Code: Select all

  m328p = ATMEGA328P      [/usr/local/CrossPack-AVR-20130212/etc/avrdude.conf:9029]

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by soerena »

OK cool, thank you.

Do I need to hook capacitors and a 16mhz crystal up in order to burn a program with the usbtiny, or can I just connect the icsp pins to the correct pins of the atmega328 and then upload?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by adafruit_support_rick »

You need a system clock of some kind. In the "ArduinoAsISP" link I posted, an arduino timer output is used as a clock.

The USBTinyISP supplies a data clock, but it does not provide a system clock.

If you are using Factory-Fresh ATmega328P chips, they come with an 8MHz internal oscillator enabled by default. They are also configured for divide-by-8 on the system clock. This means that the default configuration will run without an external clock at 1MHz. That ought to be enough to get you up and running, with no need of an external crystal.

This brings up the point that, if you want your programmed chips to be Arduino-compatible, you will have to reprogram the Fuse bytes to match the Arduino configuration (the system clock configuration, along with a few other things, is controlled by 3 "fuse" bytes. They are not really fuses - you can rewrite them. They are simply three bytes of non-volatile memory).

User avatar
phild13
 
Posts: 247
Joined: Mon Sep 10, 2012 1:05 pm

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by phild13 »

To expand a bit. Preprogramed chips such as from Adafruit that have an Arduino bootloader on them cannot be reprogrammed without an external 16mhz crystal and caps. This is because the fuse settings are set for an external 16Mhz system clock.

If you have an UNO or want to breadboard a simple circuit with a crystal and caps, then you can reprogram the preprogrammed chips for other uses.

I would just start with a blank chip, they are inexpensive, and as mentioned, come defaulted to use the internal clock, so programming them is super easy

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by soerena »

Without any external crystal or caps, I succeeded in putting this simple sketch onto a factory fresh atmega328p:

Code: Select all

void setup()
{  
  pinMode(13, OUTPUT);
}

void loop()
{
  
  digitalWrite(13, HIGH);
  
  delay(500);
  
  digitalWrite(13, LOW);
  
  delay(500);

}
But when I try to run it on a breadboard (with everything sat up according to this: http://arduino.cc/en/Main/Standalone
It only works when I have the 16mhz crystal and the two caps on.
When I remove these 3 components, the power is on but the program isn't running.
I thought the chip was using its internal 8mhz crystal, but perhaps that is only for burning programs or ?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by adafruit_support_rick »

I think the arduino hex file you used automatically updated the fuse settings to the arduino standard. If you see a file with the same name as your .hex, but with an extension of .elf, that's the fuse settings.

You can probably suppress writing the fuses with an avrdude option - offhand, I don't know what that would be.

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by soerena »

Oh, really?

I used this command to write the chip:
avrdude -c usbtiny -p m328p -b 57600 -U flash:w:myProgram.cpp.hex:i -U efuse:w:0x05:m -U hfuse:w:0xde:m -U lfuse:w:0xff:m

except the "myProgram" was my program file name, of course.

I'm looking at the datasheet for the 328p now (http://www.atmel.com/Images/doc8161.pdf), but I'm unsure where the description of hfuse, efuse and lfuse is.
Is it section 8.2 "clock sources" maybe?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by adafruit_support_rick »

Oh, so YOU changed the fuse bytes. It's all your fault. :wink:

By setting lfuse--0xff, you
-disabled clock-divide-by-8
-set a reserved value or clock start-up time
-selected the low-power crystal oscillator as a clock source.

See section 28.2 of the datasheet for the fuse bytes

The factory default values are
efuse 0xff
hfuse 0xd9
lfuse 0x62

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by soerena »

Ah yes I just realized as well :p

I tried setting the fuses back to standard, but the program will still only work with a 16mhz crystal and 2 caps connected.. hmm.. will have to study the datasheet and section 28.2 some more.

Thank you very much for your kind help so far Rick

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by adafruit_support_rick »

This fuse calculator will help keep you from pulling out your hair
http://www.engbedded.com/fusecalc

User avatar
soerena
 
Posts: 57
Joined: Fri Nov 16, 2012 7:00 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by soerena »

I was just wondering: what is the point of setting the CKDIV8 bit so that the chip will run at 1mhz instead of 8mhz? Wouldn't 8mhz be much faster?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: USBtiny with atmega328: How to hookup, and Avrdude 5.5

Post by adafruit_support_rick »

Speed isn't important in some embedded applications. Power consumption will be much lower at 1MHz. Mainly, the defaults are intended to make the raw chips compatible with a wide variety of programming devices.

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

Return to “USBtinyISP”