Self Programming AVR
From Bob's Basement
Stage: Proposal
Who: naxxtor
This project is to make a very basic AVR development board which can self program using RS232 or USB, similar to the PICAXE range, mainly used for rapid prototyping, experimentation and teaching. Oh, and it all has to be open source.
Contents |
[edit] Why
AVRs are a great microcontroller platform, but in order to start working on them, you need to have a programmer to hand already. Also, if you're working with SPI interfaced things, having to plug and unplug the programmer gets old, fast.
Many BB projects would benefit from an inexpensive development board (not dissimilar to an Ardunio in terms of hardware) which you can load programs onto without having your own programmer. This would be especially useful for group workshops and such, where all someone needs to play with the controller is a free USB port, avrdude and the board.
[edit] How
ATMega168 and other AVRs have a feature called SPM, or Self Programming Memory. This allows them to run a bootloader. A bootloader is run when the chip is reset initially - the default one will allow the chip to be programmed using the usual ISP connection from a programmer.
It is possible to flash your own bootloader onto the chip. This is done by generating a .hex file for the bootloader and using an existing programmer, and using avrdude (or another piece of flashing software) to flash the chip, and then update the fuse-bits telling the AVR where the bootloader is. The default bootloader is at 0x0000, but the custom bootloader will be at another location.
This process is described here: AVR Bootloaders
From that page, the bootloader called STKLOAD looks very interesting. This bootloader emulates a stk500 (a very common programmer) for the first 3 seconds of power on. This allows an RS232 connection to be made to a PC and firmware re flashed without using a separate programmer.
This isn't the end of the story, though, as we need a development board to go around it. Ideally, we want to take advantages of the 168's features, and make a useful board.
It needs the following features:
- GPIO ports (C and D) available
- RS232 connection
- Reset button
It would be good to have the following features:
- SPI interface available (plug and play periphrials!)
- A couple of "high current" outputs supported by transistors
- External clock interface (for tweaking)
- Isolated analogue inputs
- USB interface
- Pluggable pin layout for plugging into a breadboard
- Blinky lights might be nice
[edit] Price
It's not going to cost much to build. The expensive parts are going to total about about £5, including USB controller. In total, it's going to be about £5.50. /* insert a proper price breakdown here */
[edit] USB
If we want to use USB, which is probably the most practical method of interfacing given that most peoples laptops don't have serial connections any more, then we will need a USB->RS232 converter chip.
The one that comes to mind that I've seen in a number of devices (in particular my USB GPS dongle thingy) is the FutureTech FT232R. It's available in a couple of different packages, surface mount only. The only place that I've found stocking it is Crownhill, and it's probably going to be the most expensive chip on the board.
Alternatively, people can use a USB to Serial converter dongle, which is a useful thing to have anyway. However it'd be nice to have the board use USB as the connectors are smaller and take up less space.
[edit] Software
Using the STKLOAD bootloader, it should be possible to use any usual flashing software (such as avrdude) to flash the chips.
It might be nice to make a liveCD with avrdude already installed and configured for the m168 for lab environments.

