An mbed can be used for In-System Programming [ISP] of AVR microcontrollers over a simple three-wire SPI interface.
The current version uses the simple AVR910 protocol to flash the Atmel chip.
The programmer should work with any AVR microcontrollers that support In-System Programming.
This example will run through programming an ATmega328 with the mAVRISP program.
The Arduino IDE can be used to compile code for the ATmega328. The example Blink program that comes with the Arduino IDE can be compiled by first selecting the appropriate target [in this case an ATmega328 (running at the default internal 8MHz oscillator)]:

And then selecting Sketch -> Verify/Compile:

Under Windows XP the resulting output files can be found in the following directory:
\Documents and Settings\username\Local Settings\Temp\build[number].tmp
This directory will contain a .HEX file with the same name as the sketch. In this case, the name of the file is Blink.cpp.hex. This can be converted to a raw binary file using the free tool hex2bin. Note that you will have to rename the file from name.cpp.hex to name.hex:

The ATmega328 and mbed are now connected up as follows:

Put the AVR binary and the mAVRISP binary [in that order - otherwise the mbed will try to run the AVR binary!] onto the mbed. Ensure that the AVR binary is either appropriately named according to the #define PATH_TO_BINARY in AVR910.h or pass in the name you're using to the program method (see below).
If you open up your favourite serial terminal program you should see the following output when you reset the mbed:

Put an LED and appropriate resistor across digital pin 13 on the ATmega328 and watch it blink!
| Atmel Pin | mbed Pin |
| MOSI | p5 |
| MISO | p6 |
| SCK | p7 |
| nRESET | p8 |
| VCC | Vout |
| AVCC | Vout |
| AREF | Vout |
| GND | GND |
No tags
|
1 reply
Please login to post comments.
Hi, I really like what you have done here!
One hex2bin conversion can be done with avr-objcopy: avr-objcopy -I ihex foo.hex -O binary foo.bin
I got this working on mega88, but I had to divide ATMEGA328P_PAGESIZE by two. I that way it will give the correct word count and magically it stated to work. Found it on some other forum having this kind of subject.
I'm very thrilled, now I can use mbed as a field programmer. :)
Thank you for your hard work!