Saturday, July 24, 2010

Using Duemilanove to Program the Cricket


As promised, this will have pictures, though not necessarily great ones.

After finding a what seemed like a great deal on ebay, An arduino compatible When I got it I realied that the header to turn the top left port into a 10-pin standard ISP header wasn't included (as my plan was to order a serial port ISP10 programmer), I really wanted to figure out how to make the board useful.

To the left is the Cricket with labels on it, note that my particular one has a Serial flash and a 10MHz crystal. First of all, a general description, I consider this board to be turned 90 degrees clockways from normal orientation. (This was done so most pins can be labeled.) The pins are labeled via Arduino(/Sanguino, I'll get to that later) pinout. For right now, what we want to do is program the chip. The pins we need are marked in the upper left of the image.


Atmega processors are programmed using In-system programming, which normally uses a 6 or 10 pin header carrying the required information. (Though the 10-pin doesn't use all of them.) If you look at the picture of the Arduino Duemilanove, you will see a 6-pin header on the right, this is for ISP programming of the chip. The pin out has a pin for Reset, Serial Clock (SCK), Master to Slave Communication (MOSI), Slave to Master (MISO), a 5V and obviously Ground. The 10-pin adds an LED indicator, and more Ground connections.

Fortunately, Arduino is popular enough that, someone has already written an implementation of ISP programming, which is distributed in the example sketches. Called ArduinoISP, this is usually used to allow uploading just the bootloader to another Arduino, but in this case, due to the lack of USB, and my desire not to splice serial cables, I will be using this to upload sketches as well. You will find that it uses pin 13 for sck, 12 for MISO, 11 for MOSI, and 10 for reset. As well as using 9, 8 and 7 for status LEDs. (Check the file)

On the cricket, all of these functions are brought out nicely to a header, and the cricket is easily inserted into a breadboard (It's not possible to see, but the cricket is essentially stackable). I use this to make it easy to adjust which pins go where, and to make it easy for future reprogramming, I set it up on a breadboard, such that it is simple to plug the cricket back in. If you look at the first picture, you'll see there are 7 pins contained, in addition to the 4 labeled, they are 2 for power (Vcc and Ground, which in my case, must be a 3.3V, fortunately the Arduino supplies this), and one for SS, which is Slave Select. This needs to be held low, which I noticed, conveniently happens on RESET, as I read the ArduinoISP code, so I'm going to have it also go to SS, as well as reset.

So, the 7 pins, need to be connected to pins 10-13 and power on the Arduino, this is one to one, except for pin 10 to SS as I've used it, SS can also be connected to ground. (That's probably a better solution anyhow. EDIT: Not really, I just tried it and it failed to work, so just use pin 10) On the breadboard, I've connected them to a few rows on the opposite side, matching the Arduino pins, so that I can easily plug wires from the Arduino into the matching number. (I may make a diagram later, as it is counting from the top/left of the cricket's J2 connector, Arduino pin -> Cricket pin: 3.3V -> Vcc; 11 -> 5/MOSI; 13 -> 7/SCK; 10 OR GND -> 4/SS; 12 -> 6/MISO; 10 -> RESET; GND -> Ground)

Now, there is one other issue: Automatic reset. As far as I can tell, this needs to be disabled while using the Arduino as an ISP programmer. There are two ways to disable it. One is to cut a trace, which will disable it until that trace is bridged. Which seems like an annoying case (and if you want to disable it again, cut, etc.) Apparently earlier Arduinos provided a jumper. Unfortunately my Duemilanove doesn't. However, there is a much more elegant solution, which is to temporarily disable it. This is accomplished via a 110 ohm resister between reset and 5v. (In my picture, that's the two resistors in the lower left.)

Now you can try to upload the Cricket bootloader with the avrdude command: avrdude -b 19200 -c arduino -p m644 -U flash:w:BootLoader_Cricket_10MHZ.hex -P /dev/ttyUSB0 if the bootloader (obtainable from soc-robotics) is in the directory. You may also have to adjust the port (-P option). This should upload the bootloader. I believe The LED will slowly flash.

Next post will describe how to upload programs(sketches) to the Cricket and how to set up the Arduino software to handle it, due to the chip being an Atmega 644 and not a normal Arduino chip, and the difficulty of using an ISP programmer for sketches as opposed to using the bootloader. (It might be two parts.)

Oh, and just so it's clear: images in this post Copyright 2010 by James L.

No comments:

Post a Comment