It seems that we are done with Arduino/Wiring IDE port for ATMega32 and ATMega644. Code runs on both microprocessors in the exactly the same manner.

The ultimate test - if robot performs identically after the brain swap the port is successful. We upgraded robot main controller from ATMega168 (Arduino Board) to ATMega32 and then to ATMega644. And yes, the bot performed exactly the same regardless of what micro the code was running on.

Here is the micros that we were used to run the tests.

AVR ATMega 32 and 644

During the above tests the following things were observed to work properly:

  • I2C,
  • Hardware Serial,
  • ADC,
  • PWM

The archive with all the files that need to be placed in $ARDUINO_HOME/hardware/cores/arduino directory. Please, refer to our download area for more options.

ZIP content:

  • pins_arduino.c
  • pins_arduino.h
  • WInterrupts.c
  • wiring.c
  • wiring_analog.c
  • wiring_digital.c
  • wiring_serial.c

We had to patch two extra files (WIterrupts.c, wiring_serial.c) to get Arduino/Wiring IDE compiling for Mega644 in addition to the once that we already modified for Mega32. Here is the snapshot of WinMerge utility comparing original Arduino IDE directories content and our patched version.

Arduino IDE changes

What we found very interesting was that Mega644 is using identical register names to those of Mega168. This is despite the fact that Mega644 is being pin-for-pin compatible with Mega32. Go figure! However, the explanation is pretty simple, Mega644 and Mega168 are newer cores, therefore, both of them use newer register naming conventions versus older Mega32 core.

If you decided to test-drive this patch, make sure you create a backup of your $ARDUINO_HOME/hardware/cores/arduino directory and $ARDUINO_HOME/hardware/boards.txt file since you will be working with experimental code that was tested only at Robotcraft.ca lab.

After you download the ZIP and made backup of your original files, put the new files from the ZIP into your $ARDUINO_HOME/hardware/cores/arduino directory.

You will also need to add the following configuration information to your $ARDUINO_HOME/hardware/boards.txt file, so you could select ATMega32 and ATMega644 as target microprocessors from your IDE.


################################
atmega32.name=ATmega32
atmega32.upload.protocol=stk500
atmega32.upload.maximum_size=14336
atmega32.upload.speed=19200
atmega32.bootloader.low_fuses=0xff
atmega32.bootloader.high_fuses=0xdd
atmega32.bootloader.extended_fuses=0x00
atmega32.bootloader.path=atmega8
atmega32.bootloader.file=ATmegaBOOT.hex
atmega32.bootloader.unlock_bits=0x3F
atmega32.bootloader.lock_bits=0x0F
atmega32.build.mcu=atmega32
atmega32.build.f_cpu=8000000L
atmega32.build.core=arduino

################################
atmega644.name=ATmega644
atmega644.upload.protocol=stk500
atmega644.upload.maximum_size=14336
atmega644.upload.speed=19200
atmega644.bootloader.low_fuses=0xff
atmega644.bootloader.high_fuses=0xdd
atmega644.bootloader.extended_fuses=0x00
atmega644.bootloader.path=atmega8
atmega644.bootloader.file=ATmegaBOOT.hex
atmega644.bootloader.unlock_bits=0x3F
atmega644.bootloader.lock_bits=0x0F
atmega644.build.mcu=atmega644
atmega644.build.f_cpu=8000000L
atmega644.build.core=arduino

You may need to adjust atmega32.build.f_cpu/atmega644.build.f_cpu lines and specify appropriate clock speed that micro is running at. Ours was running at 8MHz.

We used Arduino/Wiring IDE ONLY to compile and generate HEX files, so the code uploading functionality of the IDE is not tested at all. We used ISP to transfer the code. For what we know the lines that start with atmega32.upload and atmega32.bootloader simply might be all wrong. Same applies for equivalent lines for atmega644 configuration.

Once we get some more time, we will look at the bootloaders for 32 and 644 Megas as well as fix these config portions. But for now, it's experimental code ;-) . You are free to help and fix it.