Using an ATMEGA328p to program another ATMEGA328p

Hi Forum,

So I'm trying to program an ATMEGA328p using another ATMEGA328p fetching the program from an external I2C EEPROM.

I have found links like these Gammon Forum : Electronics : Microprocessors : Atmega chip stand-alone programmer to upload .hex files where they use an SD card instead of an EEPROM.

So I ask you the following:

  1. Do you know a library that can do a similar task?
  2. Can the ATMEGA328p self-program (again) itself ?
  3. What alternate method can you recommend me? That doesn't involve an SD card.

Thanks !

Hello ! Any comments? Thanks

I don't believe you can do this, due to the way Arduino is compiled, but I could be mistaken. As far as I know, you have to have code in some sort of IDE, then compile it to the chip itself. From what I've read, you aren't able to (practically) clone Arduino programming directly from the chip

I don't know of a bootloader that will take a .hex file via I2C to put into flash.
Certainly it's possible software & hardware wise, I just don't know that anyone has.

There is a bootloader that does allow a sketch to self-modify itself with calls to function kind of code stored in the bootload area (code must execute from there to write to sketch area). Perhaps that could be used.
See this topic Writing to FLASH from application. Please test and enjoy :-) - Microcontrollers - Arduino Forum

The basic methodology appears to be embedded in this logic for OTA flashing:

Code updates can be sent to a device over a radio network and saved on an I2C EEPROM. The bootloader can then flash the processor with the new code. This allows remote code updates to Arduino based radio devices.

The project is in several parts. The bootloader replaces the popular Optiboot bootloader and allows flashing of program memory from I2C flash. The run-time flash / I2C library implements a messaging system and simple file system that allows an I2C flash chip to be read and written remotely. My radionet library implements a messaging protocol that can carry the flash messages. I've also designed a PCB for a circuit that works with the code, but you can also use a JeeNode or similar device.

Ray