Getting Started with the AVR
I found the AVR to be very easy to get up and running. There are several ways to begin:1. Buy the Hardware
- Buy an Atmel STK500
- Buy components and a breadboard
- Buy my ATMEGA128 board plus an ISP or JTAG programmerMethod 1: Buy an Atmel STK500 from Digikey. You will be up and running instantly. The STK500 has sockets for all DIP versions of the AVR and has an ISP programmer built in. It can not program the 128 or 103 without an adaptor board. It has some test LED's, switches and an RS-232 port making it useful for simple testing. You will still need to connect to a breadboard for anything more complex and the STK500 will never be usable in a project. Starting with this and then progressing to Method 3 is good way to go. Total cost $89.
Method 2: Buy the parts listed below. This is the least expensive alternate and gives you a lot of flexibility for all but the 128 and 103 parts but you do need to be comfortable with electronics. You can get most of the parts from Digikey - they have a $25 minimum subject to a $5.00 surcharge, will ship USPS for $3 or $4. Here's the list:
- A couple AVRs. Anything from an AT90S2313 up to an ATMEGA163 will work fine.
- A couple crystal oscillators - 8 MHz and 7.3728 MHz (Digikey 300-6016-ND and 300-6015-ND, 88 cents ea.)
- A breadboard - Radio Shack or Jameco have a good assortments, .100" pin spacing, only need about 2" x 4" to get going.
- A couple LEDs (Digikey 160-1080-ND)
- A couple 480 or 680 ohm resistors to be in series with your LEDs
- A couple 22 pF capacitors
- A five volt regulated power supply (needs to be stable between 4.6 and 5.4 volts), a 5 volt DC wall wart will usually work, or a 6 volt battery pack with a 78L05 regulator.
- An ATMEL AVR ISP serial programmer ($36 at Digikey, search for AVR ISP), or, for $5 and a little elbow grease, build the parallel port programmer on PonyProgs web page and use PonyProg to program http://www.lancos.com/prog.html.
- Six pin header (2 x 3) for the ISP interface (Digikey S2221-36-ND - is actually 2 x 36)
- You'll likely want an RS-232 interface - use a MAX 233 (Digikey)
- You need 2 spare serial ports on your computer
Total cost - about $65 ($35 if you go the PonyProg route).Method 3: Buy my ATMEGA128 board and buy an Atmel AVR ISP programmer from Digikey. You will have a test environment for an ATMEGA128 set up instantly and you will have a board that could be used in a project. You will likely want a couple of breadboard or wire-wrap adaptors to allow connection to external devices. If you want to work with the smaller, cheaper devices you will need to use method 2 or 3. Total cost is $55 plus $37 = $92.
Thats it! No more money.
2. Physical installation - This applies to the Buy Parts method only. Skip this if you are buying my board or an STK500. Plug the AVR chip into the bread board, refer to the pinout diagram from the appropriate manual (find them on Atmels web site) and wire up the following pins:
AVR Pin What to connect to it3. Flash Programming software - download AVR Studio from the AVR website. You need the 3.52 version or later to get AVR ISP support. Install software on your PC. Connect the AVR ISP to your serial port and then to you ISP port on your breadboard. Power up your AVR. Fire up AVR Studio and it should find your micro. See if it reads your chip signature properly - that indicates all is working OK. Find a sample ROM file and load it into the AVR flash - hopefully it does what it says.
Vcc 5 VDC
Reset 10K to Vcc, switch or jumper to ground
ISP connector pin 5
Xtal1 / Xtal2 Crystal goes across these two, a 22 pf cap from each to ground
MOSI ISP connector pin 4
MISO ISP connector pin 1
SCK ISP connector pin 3
ISP connector pin 2 to Vcc
ISP connector pin 6 to gnd
Rxd MAX233 receiver (refer to the MAXIM literature for connection info)
Txd MAX233 transmitter
PD5 through 680 ohm resistor to LED to ground (could be any output pin)
4. Development software - I use GCC. Its free, its ANSI standard C and it works very well. Download a Win32 easy load version from AVR Freaks website http://www.avrfreaks.net/AVRGCC/index.php - go to the GCC tab and read up. Load the software. This is basically a DOS application that you run from a Window. You can also try assembly language - use AVR Studio. AVR Studio is also a software similator that works quite well.
Imagecraft makes a good C compiler (I used the 68HC12 version) for about $200. This may be a better choice if you are uncomfortable with the lack of vendor support that a public domain language such as GCC has. The other popular C compiler is Codevision, about which I know very little.
There are some Basic compilers out there but they don't seem to be common.
If you don't know C, then find a good C book and dig in. I won't say it's dead simple but once you've got it you're in. I switched from the Motorola 68HC12's to the AVRs and hardly missed a beat because I was using ANSI C for both.
5. Programming editor - AVR Studio is a pretty good "C Aware" editor and its beginning to work pretty well with GCC. I have used PFE, Imagecraft, Borland, can use Notepad in a pinch. I am now using Crimson Editor, a good freeware editor. A "C aware" editor is nice - it highlights different parts of your code.
6. Write a program. Find some samples to begin with. Use you editor. Once you think you have something worthwhile, try to compile it with GCC. I like to install a batch file in the GCC main directory that changes the directory to my current program directory. You need to set up the makefile. Then run "make" and GCC will attempt to compile the program. It will list all the errors, you go fix them, back and forth until no more errors. You then load the ROM file that you created into flash and see what happens.
Atmels web site - device manuals, app notes
AVR Freaks web site - discussion groups, 3rd party stuff
The C Programming Language by Kernighan and Ritchie is the classic
Lots of C info on the web