Bootloader and downloard program to 328P with USBASP

Hi,

I bought a couple of atmega328p chips, 2 with Arduino bootloader, 1 without. I also bought a Usbasp from ebay (says LC soft v 2 on it) As a newcomer to Arduino I am testing booloading the chips and want to load programs directly using usbasp.

I installed the drivers for usbasp, setup a breadboard with the new non-bootloaded chip (connected vcc, gnd, miso, mosi reset sck etc), wired the usbasp 10 pin cable with jumper wires to the breadboard.

I opened a command prompt, then went to the dir where avrdude is (v 5.11) These commands run without a problem, even though avrdude complains with this: avrdude: warning: cannot set sck period. please check for usbasp ( I read a couple of posts about this already and somewhat understand what the issue is)

This connects to the chip without issue and reports on fuses etc avrdude -v -CE:\programs\arduino\arduino-1.0.5\hardware\tools\avr\etc\avrdude.conf -c usbasp -p m328p

A similar erase command works too. avrdude -CE:\programs\arduino\arduino-1.0.5\hardware\tools\avr\etc\avrdude.conf -c usbasp -p m328p -e

I tried the command to set fuses, and that works too. avrdude -v -CE:\programs\arduino\arduino-1.0.5\hardware\tools\avr\etc\avrdude.conf -c usbasp -p m328p -U lfuse:w:0xFF:m -U hfuse:w:0xD6:m -U efuse:w:0x05:m

Burning the bootloader through arduino software works.

BUT when I try to load a hex file (I took a hex file for blink the arduino software compiled) IT does not work and behaves just like the first command I wrote above, reporting what the chip and fuses are.

avrdude.exe -v -c usbasp -p m328p -CE:\programs\arduino\arduino-1.0.5\hardware\tools\avr\etc\avrdude.conf –u –U flash:w:"E:\electronics\AVR\Blink.cpp.hex"

I tried many variations of this to troubleshoot, but can't get it to work. I tried deliverately putting a wrong path, that changes nothing and does not report an error in avrdude either. I am not sure what I am doing wrong. I realize I am new at this and it might be newbie mistake....

  • Is it because I am using the arduino software avrdude config and version?
  • Is is because I have a mistake in the command line?
  • The sck error?

Thanks and best wishes.

Once you have set the processor fuses to expect a external crystal you can no longer use serial programming until you supply the expected crystal.

The thing is I changed the fuses, but changed them back.

I did add a 16 mhz crystal to the bread board along with the caps before I changed the fuses. I will verify my setup for errors.

I will try downloading again after setting the fuses to the same as an Arduino bootloaded chip. YOu should still be able to download with internal crystal right?

Checkout Nick Gammon's "board detector" software download from here: http://www.gammon.com.au/forum/?id=11637

DroidDr: You should still be able to download with internal crystal right?

Yes. If the system oscillator is set to the internal 8 MHz oscillator you can do serial (ICSP) programming with or without an external crystal.

I finally found my problem after banging my head on this for 2 more hours.

I checked what commands arduino software sends to avrdude. First it sets lock bits and fuses then it sends a command like this.

avrdude -CE:\programs\arduino\arduino-1.0.5\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cusbasp -Pusb -Uflash:w:E:\programs\arduino\arduino-1.0.5\hardware\arduino\bootloaders\optiboot\optiboot_atmega328.hex:i -Ulock:w:0x0F:m

I run this at the command prompt and it works (no surprise there) I then check my command, edit it and start changing things one by one: forward flashes vs backwards flashes were a little different.

Nothing was working until I pasted the part starting at -Uflash till the end of the line. My command was working. I checked character by character and found nothing different, until I opened the file with a hex editor.

THe hyphen was UNICODE (ASCII E2 80 93) in my command where it was normal in the string that was working...

THat was my strangest problem in a while, glad I could solve it. Pretty f....up :grin:

I can now upload compiled sketches to my 328P on a breadboard, and proved it works by using blink at different rates.