blog.kfish.org

My name is Conrad Parker, and I live in Kyoto, Japan. I am working towards a PhD in Computer Science at Kyoto University, finishing September 2009. I also work on some free software projects including the Sweep sound editor and the Annodex media system, and various smaller projects which you can read about here.

Wednesday, 7 February 2007

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: ,

1 Comments:

Blogger Adam said...

Sweet. I've been banging my head against the clock problem all day; this fixed it in no time flat. Thanks!

21 January 2008 09:28  

Post a Comment

Links to this post:

Create a Link

<< Home