Close

Updating the AVRs over I2C

A project log for Wild Thumper based ROS robot

My ROS (Robot Operating System) indoor & outdoor robot

HumpelstilzchenHumpelstilzchen 01/19/2018 at 07:120 Comments

The wild thumper has an AVR Atmega32 and an Atmega328 microcontroller. Normally to flash a new firmware onto them I have to open the upper panel and attach my ISP. To workaround that I developed an I2C bootloader. After setting the fuse bits "Boot Reset vector Enabled" and "Boot flash section size"=1024 words the bootloader is programmed into the AVR.

On start the bootloader checks if the first byte in the flash is 0xff. If it is 0xff it assumes that the memory is erased and there is no valid program. Else it starts the main program by jumping to address 0x00. There is also the option to force the bootloader to run by writing the magic number 123 into the first address of the eeprom. When the bootloader runs it accepts commands from I2C (defaults to address 0x50/0x28). Commands include

I also wrote the corresponding client program which runs on the Linux computer. With this python script programming an AVR becomes to

./bootloader.py 0x52 main.hex -j

 First argument is the target address 0x52 (0x29), second argument is the program file to flash, -j tells the bootloader to start (jump to) program after flashing.

From now on I can update the firmware of all microcontrollers in the field without taking everything apart or attaching an extra programmer.

Discussions