| getting started with AVR microcontrollers
on mac OSX These instructions will tell you how to get the hardware and software you need to start programming AVR microcontrollers with your mac. this software will allow you to program AVR microcontrollers in the C programming language using the gcc compiler. all of the software (except for the USB-serial driver) is free. Update summer 2007: Ignore the software install instructions!! Download the nice package from OSX-AVR at: http://www.digithink.com/OSX-AVR. This should work on Intel and PowerPC macs. Then download my sample code: avr_sample_code.zip, and follow my instructions for setting up your hardware. what you will need:
setup the necessary software on your mac This install worked on my g4 powerbook with Xtools 2.1, Mac OSX 10.4 (Tiger), and the versions of binutils, gcc and avrlibc indicated in the text. You may run into problems in other situations. Please email me at buechley at cs.colorado.edu if you know of any helpful updates and I'll post them. Last updated fall 2006. 1. install the mac developer tools (XCode). These are available on your mac os x install cd, or from apple at: apple developer tools. 2. add /usr/local/bin to your "PATH" open the Terminal application. this application can be found in your Applications/Utilities folder. the Terminal application is the Unix interface to your mac computer. now you will create or edit your "PATH" variable. how you access the PATH variable depends on the type of Terminal you're running, your "shell". You can tell what shell you're running by looking at the text at the top of your Terminal window. The top should read something like this: "Terminal - csh - 80 x 20". The middle part of this text describes what type of shell you're running, in this case the c shell (csh). The following instructions work only for the c shell. If your Terminal isn't running a c shell, you need to change your shell. To do this, open the Terminal preferences, and under the "When creating a new Terminal window" section, select "Execute this command" and type: "/bin/csh" in the box. quit and reopen Terminal. Don't proceed to the next step until you're running a c shell. For more information on shells, check out Wikipedia's Unix shell page. now, to create your PATH variable:
- in the editor (in Terminal) that opens up, type these two lines: set path = ( $path /usr/local/bin ) set path = ( $path . ) - hold down the ctrl and x keys to close the file - at the prompt asking you if you want to save the file, type y and then return - double check that the file is there and is correct by opening it. type: open -e ~/.cshrc - close the file - quit the Terminal application and reopen it
- add these two lines to the file that opens: set path = ( $path /usr/local/bin ) set path = ( $path . ) - save and close the file - quit the Terminal application and reopen it 3. download & install binutils (an essential utility for the C compiler) - download the current release of binutils from : http://www.gnu.org/software/binutils/ - decompress the downloaded file and put the decompressed folder in your home directory - open up a Terminal window and navigate to the binutils directory. type: cd binutils-2.16.1 (or whatever you downloaded) - configure binutils for AVR. type: ./configure --target=avr - compile binutils. type: make - install binutils. type: sudo make install (you will be prompted to enter your password) 4. download & install gcc (the C compiler) - download the current release of gcc from: http://gcc.gnu.org/mirrors.html - decompress the downloaded file and put the decompressed folder in your home directory - create another directory to install gcc into. in a Terminal window in your home directory, type: mkdir gcc-4.0.2_avr_installation (substituting your gcc version for the 4.0.2) - navigate to the folder you created. type: cd gcc-4.0.2_avr_installation (or whatever you named your folder) - configure gcc for AVR. type: ../gcc-4.0.2/configure --target=avr --enable-languages=c --disable-libssp (substituting the name of the folder you decompressed for the gcc-4.0.2) **thanks to Seth Raphael for the --disable-libssp tip - compile gcc. type: make CC="cc -no-cpp-precomp" - install gcc. type: sudo make install 5. download and install avr-libc (an essential C library for AVR chips) - download the current release of avr-libc from : http://savannah.nongnu.org/projects/avr-libc/ - decompress the downloaded file and put the decompressed folder in your home directory - in a Terminal window, navigagte to the avr-libc directory. from your home directory type: cd avr-libc-1.4.2 (or whatever you downloaded) - configure avr-libc. type: ./configure --host=avr - compile avr-libc. type: make - install avr-libc. type: sudo make install 6. downlaod and install avrdude (the software that loads programs from your machine onto the chips) - download the current release of avrdude from : http://download.savannah.gnu.org/releases/avrdude/ - decompress the downloaded file and put the decompressed folder in your home directory - in a Terminal window, navigagte to the avrdude directory. from your home directory type: cd avrdude-5.1 (or whatever you downloaded) - configure avrdude. type: ./configure - compile avrdude. type: make - install avrdude. type: sudo make install 6 (note). you can use UISP instead of avrdude to program your chips, but I recommend avrdude. as of summer 2006, UISP does not support the latest version of the STK500 firmware. click here for instructions on installing UISP & downgrading the STK500 firmware. 7. download some sample code so that you can get started programming: avr_sample_code.zip. set up the necessary hardware 1. install the software for your USB-serial adapter and restart your computer. 2. get the name of your USB-serial adapter and edit your makefile so that it contains the right name. - plug the adapter into your computer. - open up a Terminal window and type: ls /dev/cu.* this command will return a list of serial ports. when the adapter is plugged in, one of the listings should look something like this: /dev/cu.USA19H1b1P1.1. this is the name of your adapter. - open the makefile you downloaded in a text editor like TextEdit. - in the section beginning # command to program chip, tell your computer the name of your USB-serial adapter by replacing the text /dev/cu.USA19H1b1P1.1 with the name of your USB-serial adapter. 3. set up your AVR programmer. - plug it in, turn it on and attach it to your computer via the USB-serial adapter. - read through the user guide that came with the programmer. program your chip 1. edit the makefile to reflect the chip you're working with. open up the makefile that you downloaded. replace each instance of "-mmcu=attiny13" with "-mmcu=NAME OF YOUR CHIP HERE". similarly edit each instance of "-p t13" 2. compile the code. put the folder you downloaded in your home directory. in a Terminal window, navigate to that folder and compile the code. type: make 2. plug your chip into the board. 3. load the code onto your chip. type: make install for more information Atmel Corporation: where you'll find datasheets for chips AVR LibC reference C programming language reference AVR Freaks: online community of AVR programmers AVR programming for mac OS X reference (my page is an updated version of this great reference) AVR programming for linux reference WinAVR: a Windows suite of gcc programming tools for AVRs This material is based upon work supported by the National Science Foundation under Grant No. 0326054. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation (NSF). |