Instructables

Step 10: Program the microcontroller

hfuse.png
IMG_4172.JPG
IMG_4173.JPG
If you are experiencing problems with speed and/or some LEDs not lighting up. Please read this step carefully.

To program the microcontroller, I use avrdude and the USBTinyISP programmer.

My examples will be on an Ubuntu Linux system. The procedure should be pretty much identical on Windows, but I can't help you with that. If you use another programmer, read thet manual for that programmer and avrdude.

First off, Let's just see if we can make contact with the AVR.

Connect the programmer to your cube and your computer.

The command is "avrdude -c usbtiny -p m16", wherer -c specifies the programmer, and -p the AVR model. You can see the output in the images below.

Now, upload the firmware: "avrdude -c usbtiny -p m16 -U flash:w:main.hex".

By now, the cube should reboot and start doing stuff. It will be running at 1mhz (very slowly) using it's internal oscillator. And some of the leds won't work, because some GPIO ports are used for JTAG by default.

To enable the external oscillator and disable JTAG, we need to program the fuse bytes:
run "avrdude -c usbtiny -p m16 -U lfuse:w:0xef:m"
and "avrdude -c usbtiny -p m16 -U hfuse:w:0xc9:m".

Be carefull when doing this step! If you get it wrong, you can permanently destroy your microcontroller! If you are using another microcontroller than the ATMega16, be sure to read the datasheet carefully before changing the fuse bytes!

After writing the correct fuse bytes, the cube should reboot and start operating at regular speed with all leds operational.

Enjoy your new cube :D

 
Remove these adsRemove these ads by Signing Up
Zaman2 years ago
got my atmega 16 dead after giving this command on avrdude
"avrdude -c usbtiny -p m16 -U lfuse:w:0xef:m"
the avrdude showed the command successful and when i gave next command
"avrdude -c usbtiny -p m16 -U hfuse:w:0xc9:m"
the chip is gone. i used different softwares eXtreme Burner - AVR and Khazama AVR Programmer but both are not decting the m16. ANY SUGGESTIONS.
jyraff2 years ago
Hello! Who can give me a PCB file/image? Thank you.
00bunge003 years ago
Did you have to build the TinyASP?
bkeaton3 years ago
run "avrdude -c usbtiny -p m16 -U lfuse:w:0xef:m".

Since the author indicates chip destruction if not done correctly, is the character before the word "fuse" a lowercase "L" or an uppercase "I"? Big difference...
bkeaton bkeaton3 years ago
I got this bad boy built. It is amazingly cool. Now, on to the 8x8x8...

BTW, it is a lowercase "L".
StevieLaner3 years ago
Hi,
I'm having trouble with setting the fuse bytes on my ATMEGA16 16PU.
I plugged the chip in, made contact with it, uploaded the hex firmware fine, but after I set the lower fuse byte I noticed my green LED connected to PB0 (pin 1) stayed lit and after I set the higher fuse byte it went out. I tried to reestablish contact with the chip again but it comes up with this error message:
"avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check."
I fear the chip is destroyed, but have no idea how since I followed the instructions and even copied and pasted the fuse byte code to be sure they're right.

Any ideas what could be wrong?

Stevie
febinjohn3 years ago

I made the cube but not working only the status leds are blinking

i am using mega32 t i can use same fuse as 16 ???


in high only SUT0 is high and in low SPIEN ,BOOTSZ1 and BOOTSZ0 is high

please somebody :-(
joaopsl994 years ago
i found this cheap USBtinyISP in ebay.
http://cgi.ebay.co.uk/USBtinyISP-AVR-ISP-Atmel-Programmer-Arduino-bootloader-/170474128004?pt=LH_DefaultDomain_0
 
Since I live in Europe its a lot cheaper to buy this one than the one from the site. do you think this is compatible with avrdude. it seems to me that the components are the same, only in a different layout. thanks for the instructable
please share for me code written by assembly. contrac me with vudinhthanh24h@gmail.com or messeger id: dynhanh24.
jojojoris4 years ago
Thanks for this great instructable.

This is the one i made in 2 days. (programmer + Led cube)

Hi, I have a question. Does it mater what Atmega16 microcontroller I use, and if it doesn't do I just wire it like in the schematic. thanks and please get back to me ASAP.
Nooooooooooo!

After hour, nay days of work I'm stuck on the last few metres.
I've checked my circuits over and over again and cannot find a problem, but avrdude tells me there seems to be a connection problem, it fails to retrieve the uC signature. I used an ATMega16PU.

I'm using a http://www.matwei.de/doku.php?id=en:electronics:usbisp and this is some verbose output from avrdude.

I really hope somebody can tell me what might be the problem.

C:\Program Files\WinAVR\bin>avrdude.exe -c stk500v2 -p m16 -P com1 -vvvv

avrdude.exe: Version 5.5, compiled on Jun 9 2008 at 14:32:04
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
System wide configuration file is "C:\Program Files\WinAVR\bin\avrdude.conf"

Using Port : com1
Using Programmer : stk500v2
AVR Part : ATMEGA16
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :

Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack

eeprom 4 10 128 0 no 512 4 0 9000 9000 0xff 0xff
flash 33 6 128 0 yes 16384 128 128 4500 4500 0xff 0xff
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
calibration 0 0 0 0 no 4 0 0 0 0 0x00 0x00

Programmer Type : STK500V2
Description : Atmel STK500 Version 2.x firmware
Programmer Model: AVRISP
Hardware Version: 15
Firmware Version: 2.10
Vtarget : 0.0 V
SCK period : 6.6 us

avrdude.exe: stk500v2_command(): command failed
avrdude.exe: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude.exe done. Thank you.

Any ideas? Thanks in any case for the great instructable.
If I can find some webspace to host the files, I'll be happy to share my schematics. (I'm sure they're correct)
Do you have the AVR fuses set for an external clock source, if so are you providing the proper frequency to the micro? I have that issue when I started using my new programmer too.
Thanks mate. Much appreciated. But I hang my head in shame and admit that it took me quite some time to realise that my IDC header for the ISP connection was soldered on incorrectly. I managed to build my board with the connection on the wrong side, so "simply" turning the header around isn't enough and there are no solder eyelets on the upper side of my protoboard. Built myself a bugfix adapter cable with twisted pairs (pin 1&2, pins 3&4 etc crossed) and now it all works like a charm. Now all I have to do is replace one dud LED (luckily in a corner of the cube) Interestingly they all worked when I checked the cube on completion about a week ago. I hope this isn't a bad omen of things to come and my el-cheapo LEDs off eBay are all going to die on me in no time. Fingers crossed Thanks again to chr for the excellent instructable.