Author Options:

need help with programming Answered

im new at programming microcontrollers and im trying to program an attiny13. i have the cradle and a USB Programmer but im really confused on how to add the code to the microcontroller. i tried to download a sample version here to test it out but i dont understand what im looking at (the code i want to test with is called test_leds.hex( this just makes the leds flash to test it) and its near the bottom under "pulling it together".

i downloaded the WinAVR program which i believe is used to right the code and im using the notepad it came with to right the code but i dont understand how to transfer that code to the microcontroller and i cant seem to make it into a hex file.

can anyone tell me what steps i need to take to program the attiny13? and how to use avrdude and to make hex files with winavr? i know its a lot to ask but i seriously want to learn how to do this.



9 years ago

Get avrdude to communicate and recognize the ATtiny13 (before you compile and upload a program.)

The ladyada link indicates that the programmer type is usbtiny. And the avrdude name for the AVR is t13. Try this (in a command prompt or shell window, ala DOS):
avrdude -c usbtiny -p t13
This link on ladyada's site has more detailed info. Look there for the possible responses you'll receive.

Once you get the computer--programmer--AVR link working, then move on to writing and compiling the code....

ok it detected both the programmer and the t13. do i need to turn the code into a hex file to be able to upload it to the t13 and if so how do i make the hex file? is winavr notepad able to turn it into a hex file cause when i tried it with one code but it didnt save as a hex.

Have you got AVRStudio installed? (download from Atmel.) You can create a project, import source files, configure for the target AVR, then "build."

Once you build, or compile the project, the hex files should be in the "default" directory, inside the project directory.

With the usbtiny programmer, you'll probably have to use avrdude directly, just like guyfrom7up.

Guyfrom7up, in fact, is probably the right person to help you....I've used AVRStudio a couple times, but generally I do everything in Linux. That involves editing source files in a text editor, then compiling the source with a Makefile in the shell, rather than doing it all within a development environment....

guyfrom7up said that you helped with his and he told me to ask you for help. you think you can with avrdude?

Sure, but it's kinda of a busy day. I'll get back to you this evening. Maybe someone else will help before then. Have you got a hex file built in AVRStudio?

Try this to program an ATtiny13 with your ISP hardware, and the hex file name of "myprog.hex":
avrdude -p t13 -c usbtiny -e -U flash:w:myprog.hex
The hex file would be in the current directory (obviously, change the file name to whatever's appropriate...)

also, I created a batch file where you don't' have to type in that code. ' I called it upload.bat so all you have to do in CMD is say: upload youprogram where yourprogram is you .hex file, except you don't need the .hex after that you just type in the AVR you are using. the only problem is the code only works for my programmer, but you might be able to do just a find and replace to make it work for yours. This is my first batch file (made a couple months ago), so it's probably poorly written (still works though!) and highly unorganized.

ok it sees the attiny13 but after i enter it goes straight to the download without me having to choose what file i want to upload.

first off, did you edit the bat so it will work with your programmer (I don't know how easy this will be to do ???) the action (in the cmd window) upload blinky where blinky is just the name of your program. then you type in attiny13 I also made it so that a simple robot could program a bunch of AVRs simply by hitting the keyboard, so to exit the program you have to hit ctrl+c

k i tried this method but after it read the "on-chip flash data" it came with an error saying
"verification error, first mismatch at byte 0x0040
0xa0 != 0x0d
verification error; content mismatch"
this is the test led i was trying to load to see if my attiny was still working and thats when it came with the error. any idea whats going on?

The "test_leds.hex" file link is the same one from ladyada's avrdude tutorial. But that was compiled for the ATtiny2313, not the ATtiny13.

That's a little like trying to load a Mac program on a PC. Not gonna work. The AVRs are not quite so radically different, but the two are different enough that it won't work.

You need to find a tiny13 hex file, or compile a C source file for the tiny13 in AVRStudio (and use that hex file.)

Guyfrom7up and I collaborated on an ATtiny13 project here on instructables, if you want try that hex file: Lucid Dream Machine.

alright it worked. now i just need to see if it will work from the chip.

Reading the flash memory back from the chip? There's usually no reason to do so... But it's easy enough, use the 'r' switch, instead of 'w'.

no i mean if the chip will work with the leds and switch and all that after uploading the code.

OK, I gotcha. If you didn't get any error msgs, it's very likely you're good...

You can probably just use the built in programming function of avrstudio4. But for that you have to find the C code. Or you could just use AVRdude. Try googling these. For my AVR programmer I have to use AVRdude because avrstudio4 won't recognize my programmer

i got avr dude running but i cant find the port my programmer is on. and im not even sure if its seeing the attiny13 and im not sure where it indicates that it sees it.