How about making one of the countless serial AVR programmers and using it to write the Arduino firmware? This one worked for me, but I have USB to serial converter, so it works at amazing 3 B/s. If the programer lines on your other project are available, you can dump firmware using AVRdude. You could also probably get it form the Internet, but I don't know where to look
I suspect the problem is not with your C code but with your Makefile.
The following lines in your Makefile produce an example.o
object file.
main:
avr-gcc -g -Os -Wall -mmcu=atmega328 -c ../src/example.c
The created .o
file only contains the symbols and code from example.c
, not the additional source required to actually make it run on a target system such as interrupt vector jump tables and code to initialise the BSS RAM segment to zeros, and load your initialised data sections.
You'll need to add an additional line something like this to run the linker and produce an output object suitable for download to the AVR part. Alternatively, use avr-ld
, but you'll have to work out all the required linker options.
main.elf: example.o
avr-gcc example.o -o main.elf
You can use avr-objdump --disassemble-all <filename>
on both example.o
and main.elf
yourself to verify the different content of each file.
It's always a good idea to try to reduce your problem in steps to the most simple example possible. In this case, it would probably mean dropping into the AVR Studio software and creating a project running on the simulator using their managed build process. From there, you could them export the Makefile in use by their build process by using the 'Export Makefile' menu option. The generated makefile could then be compared with your version.
Actually, it's probably a good idea to use a Makefile similar to the one generated by AVR Studio because it has the correct rules already defined, you just have to set up some variables with regard to which objects need to be generated and the final target file name.
Best Answer
Honestly, my experience with AVR programmers is really quite uniform regardless of which programmer I'm using. I have used several different programmers, from the SparkFun Pocket AVR to a cheap eBay AVR programmer that cost under $5. I didn't really notice better performance coming from a more expensive programmer as compared to the cheap eBay one. I'd just try a few and see which one you work best with.