Atmel AVR ISP mkII, avrdude, Ubuntu
Inspired by Vik Olliver and Geoffrey Bennett at LCA 2007, and by seeing a class full of 9 year old Japanese kids building and programming robots (part of a field trip at C5 2007), I grabbed an AVR microcontroller and started playing.
This post just contains some gotchas for what seem to be common problems.
My aim tonight was just to build and program a simple test circuit, as outlined in Guido Socher's article Programming the AVR microcontroller with GCC. As I have plenty of USB ports but no parellel port, I bought a USB based in-system programmer, the AVR ISP mkII. My laptop is running Ubuntu 6.10 (Edgy), but most of the software required comes straight out of universe, ie. basically pulled directly from Debian.
- To use the mkII rather than a parallel port programmer, refer to the pin-out for the AVR ISP header. Add a separate Vcc line to the programmer, the rest of the circuit is unchanged.
- The cross-compiler toolchain is packaged in Debian, as is avrdude (to upload and download the code, dude):
apt-get install binutils-avr gcc-avr avr-libc avrdude
There are some buildable examples in /usr/share/doc/avr-libc/examples. - Guido Socher provides an updated tarball for the demo code in his tutorial. It contains a pre-built image and a useful Makefile.
-
To add an entry for the AVR ISP mkII to udev, add the following to
/etc/udev/rules.d/40-permissions.rules:
#AVRISP mkII SUBSYSTEM=="usb_device",SYSFS{idVendor}=="03eb",SYSFS{idProduct}=="2104",MODE="0666"(from Yuki's Linux Memo). -
Apparently the factory setting for the clock on these chips is fairly random,
so you need to set that explicitly before you try doing anything else like
uploading code. If you don't do that, then you'll get a bunch of nasty timeout
errors like
avrdude: stk500v2_paged_write: write command failed with 128.
So set the clock by dropping into the avr terminal:
$ avrdude -c avrispmkII -P usb -p m8 -F -u -t avrdude> sck 10 >>> sck 10 Using p = 10.37 us for SCK (param = 7) avrdude> quit >>> quit avrdude done. Thank you.
Labels: microcontroller, ubuntu
