0

Currently I am using avrdude and I'm programming my atmega328p chip via the spi pins by pulling the RESET pin low (spidev programmer).

In my project I'm using predominantly i2c and this the only place where spi is used. I was wondering whether it is possible to program the chip via the i2c protocol and remove the spi connections altogether?

My searches were unsuccessful.

4
  • 1
    Are you really programming over SPI (communicating via SPI with a bootloader) or are you programming via ISP (same pins)?
    – chrisl
    Commented Jan 8, 2023 at 16:58
  • @chrisl I thought I was using SPI, but now I'm not sure, lol. I'm using avrdude (-c linuxspi) to flash a .hex file over the spi pins and using the reset pin as slave select.
    – php_nub_qq
    Commented Jan 8, 2023 at 20:42
  • If you haven't changed the bootloader via ISP before doing that, I think you were using ISP, which means you were communicating with the ISP hardware of the Atmega328p directly, not with a bootloader running on it. Though I would ask, why you want to eliminate the SPI/ISP connection? Normally you use this only while developing and once for programming on production. You can even program the controller outside of your project and only put it into the target circuit after programming. That way your project circuit doesn't need any SPI/ISP connection headers.
    – chrisl
    Commented Jan 8, 2023 at 20:55
  • @chrisl Well then, I suppose I'm using ISP. I want to be able to flash new firmware to my controller at any time, thus I need the programming connections, it was just going to be nice if I could reduce the number of connections if there was a simple way but it seems like too much work.
    – php_nub_qq
    Commented Jan 8, 2023 at 21:43

2 Answers 2

2

Yes, as JRobert pointed out, I have no doubt - it is possible!

You need just 3 things:

  1. a Bootloader that supports uploading the firmware via I2C
  2. an Upload-Software that supports uploading the firmware to the bootloader mentioned in 1.)
  3. an physical connection from the system the upload software is running on to the actual I2C bus of your device

Actually the physical interface is not the problem - there are USB<>I2C interfaces available widely, you can also re-use an arduino itself to be such.

Let's look at the bootloader.

Actually I found a german site that claims having a working I2C bootloader for Atmega8 including an upload tool (use Deepl.com to translate it). It may or may not work for other Atmegas as is.

There is also another project at github.

There will be more if you google for it. Actually I have not investigated any of them.

But chances are good than any of those might work for you.

2

From section 27.2(*) of the Atmega328xx data sheet (emphasis mine):

In ATmega88A/88PA/168A/168PA/328/328P the Boot Loader Support provides a real Read-While-Write Self- Programming mechanism for downloading and uploading program code by the MCU itself. This feature allows flexible application software updates controlled by the MCU using a Flash-resident Boot Loader program. The Boot Loader program can use any available data interface and associated protocol to read code and write (program) that code into the Flash memory, or read the code from the program memory. The program code within the Boot Loader section has the capability to write into the entire Flash, including the Boot Loader memory. The Boot Loader can thus even modify itself, and it can also erase itself from the code if the feature is not needed anymore. The size of the Boot Loader memory is configurable with fuses and the Boot Loader has two separate sets of Boot Lock bits which can be set independently. This gives the user a unique flexibility to select different levels of protection.

You may need to re-write the input section of the bootloader, but it sure sounds like Atmel intended it to be doable.

[*] My data-sheet is dated 2018; the relevant section, Section 27, is titled "Boot Loader Support – Read-While-Write Self-Programming", in case a later revision has different section numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.