UP | HOME

Week7 : Embedded Programming

previous next

AVR getting started

I plunged in the AVR world headfirst. I decided to spend some time to find a way around the Arduino IDE, or basically something that replaces the straight forward IDE. There are many resources in the net about this topics few of which I will mention here. I haved worked in C/C++ previously so I expected to find my way easily in the avr-libc. But I was not totally correct with this assumption. Neither a knowlege with the Arduino programming using the much intuitive IDE would help, simply there remains a low level element in C that you have to take care off and atleast understand.

The following examples were very useful for linux users:

Arduino board with Arduino IDE

The first task was just to use a simple example in the IDE and try to replicate it in C. I followed the instructions in an online tutorial to figure out how to compile and upload the program to arduino, and I was able to replicate the results. I also found many helpful resources in the net that used the Arduino as an ISP, and Arduino provided the missing link for me since I had to skip the ISP

Arduino board with avr-libc avr-gcc and avrdude

I used avr-gcc to compile a simple blink script written in c and using the avr-libc library, I followed an online tutorials to achieve that. I thought since I will repeat those steps many times for every example c program I should creat a simple bash file to be able to do the whole compilation process of creating an object file, a hex file and uploading it to the avr in one command line.

sh test.sh led ledn atmega328p ACM0

#!/bin/bash

avr-gcc -Os -DF_CPU=16000000UL -mmcu=$3 -c -o $2.o $1.c

avr-gcc -mmcu=$3 $2.o -o $2

avr-objcopy -O ihex -R .eeprom $2 $2.hex

sudo chmod a+rw /dev/tty$4

avrdude -F -V -c arduino -p ATMEGA328P -P /dev/tty$4 -b 115200 -U flash:w:$2.hex

Date: 2015-03-30

Author: Salman Oraibi @ Fablab-Bahrain

Org version 7.9.3f with Emacs version 24

Validate XHTML 1.0