Install necessary packages
$ sudo apt-get install gcc-avr
$ sudo apt-get install avr-libc
$ sudo apt-get install avrdude
Sample code
#includevoid main() { }
Compiling code
$ avr-gcc -Os -mmcu=$2 file_name.c -o file_name.elf
$ avr-objcopy -j .text -O ihex file_name.elf file_name.hex
Uploading code
$ sudo avrdude -p part_name -c programmer_id \
>-U flash:w:file_name.hex
+ part_name => m16, m8+ prog_id => usbasp
+ "flash" => programs flash
+ "w" => write mode
+ shld be run as super user => "sudo"
Compiler optimization
specify an option -Ox while compiling (avr-gcc -Ox ... )
+ x => optimization levels
+ "-Os" => "s"=> small - for smaller code
+ x => optimization levels
+ "-Os" => "s"=> small - for smaller code
Made a video of LED blinking @ 900ms
FUSE BITS:
# read
$ avrdude -p m16 -c usbasp -U fuse_name:r:file_name.txt:h
+ fuse_name => lfuse,hfuse,lock
+ "r" => read
+ fuse value "h" in hex format
+ stored in file_name.txt file
# write
$ avrdude -p m16 -c usbasp -U fuse_name:w:0x82:m
+ "0x82" => sample fuse value
+ "m" => immediate ( use value in cmd directly )
+ "w" => write
Note: make use of AVR fuse CALC available online
0 comments:
Post a Comment