Using avrdude and an AVR microcontroller as a proxy to program another one connected to it via TWI #1930
-
Hi people. I am busy with a project of mine that involves two AVR microcontrollers, one ATmega328 and one ATtiny24/45/85. Before I finalize the release PCB I'd like to know if it is possible to use
The major feature I'm interested in is to program the ATtiny's EEPROM from the 6-pin ICSP connector (therefore using MOSI/MISO/SCK/Reset) that is physically wired to the ATmega328 right now. But I don't exclude flashing its program memory too. My priority right now is to access the tiny's EEPROM without having to desolder the chip or making it socket-able. Could that by chance be achieved by tweaking For the record I'm using Manjaro Linux². Thanks in advance and have a great day. ¹ It is understood that I am to write the required code and protocol between the two microcontrollers, and more if needed. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
Interesting problem. I don't see a way to access the ATtiny's EEPROM externally via I2C. Theoretically you might be able to write a bespoke bootloader that sits on the ATtiny, internally accesses its EEPROM and communicates with the m328 via I2C (or software USART using SDA/SCL); that might require an additional line from one of the m328's gpio to the t25's reset pin. But no, not really. I assume you thought about putting both m328 and the t25 onto the SPI bus and have a jumper on board that directs the ICSP reset line from the AVRISPmkII to either m328 or the t25? Then the jumper would decide which part gets programmed. |
Beta Was this translation helpful? Give feedback.
-
That is indeed what it's about. Although it would not really be a bootloader in my case, at least not how I see it as my first idea would be to extend the existing protocol (which I already wrote) to support data transfers, which would cause the ATtiny to read/write the EEPROM. And if there had to be a bootloader at all then I imagined it to sit in the ATmega328 instead since the ATtiny is always available via I²C and is not supposed to be reset externally. Fact its reset line is not connected (thus far). The only gray area is about how to tell
Hmmm... I didn't and it's a nice idea. It would however imply non trivial changes to the PCB though, which I'd prefer to avoid. I initially had thought about using a DIP package for the ATtiny¹ but then changed my mind for a TSSOP that I could streamline with the DIP footprint. The DIP package would be socketed but the streamlined TSSOP would then be soldered in place (although I have an adapter board TSSOP <-> DIP). I also thought about making an adapter board between the ICSP connector from the programming module with clamps, shaped like a alligator clip to latch onto a DIP-8 IC or using pogo pins to match the PCB holes. But my reflections led me to conclude the software method demands less hardware work. I'm not short of ideas, as you can see ;) ¹ So that it is programmed outside its PCB, e.g. on a breadboard. |
Beta Was this translation helpful? Give feedback.
-
Yes: bootloader on the m328 could work too. Either way, the software on the t25 would need to be well thought through and implemented as the t25 can no longer be reprogrammed once it's soldered on. Accessing the m328 bootloader normally is via its USART using an USART/USB cable to the host PC (requiring a suitable connector), and not the ICSP interface via the external AVRISPmkII programmer. |
Beta Was this translation helpful? Give feedback.
-
Exactly, you've nailed it. Now I could always build my own board but since I (believe I) am pretty close to the goal with the tools I have, I have been wondering about how to make (or hack/tinker with) |
Beta Was this translation helpful? Give feedback.
-
Given the initial setup, there is no way for AVRDUDE to talk to the t25: an unmodified AVRISPmkII programmer with a standard 6-cable connection to a standard target board would always send the m328 into reset making it an SPI periphery for in system programming of the m328 no matter what AVRDUDE does. If the project really wants to use SPI communication between the AVRISPmkII programmer and the boards's m328 then the m328's firmware would, out of necessity, operate in periphery mode as the programmer expects to drive SPI in host mode. This implies that the m328's SPI select pin PB2 should be connected to the 6-pin ISP connector instead of the m328's reset pin. This in turn requires a hardware mod, eg, a 3-pin jumper that can be set to either map the reset pin of the 6-pin ISP connector to the m328 reset (to program the m328) or to the m328's SPI select pin (to allow the m328 to operate in SPI periphery mode). When prompted by AVRDUDE, the AVRISPmkII programmer will issue a certain 4-byte communication on the SPI interface for reading from the target's EEPROM: Alternatively, the host running AVRDUDE could be connected directly to the m328 using an USB/USART cable. Selecting a bootloader programmer ( |
Beta Was this translation helpful? Give feedback.
Given the initial setup, there is no way for AVRDUDE to talk to the t25: an unmodified AVRISPmkII programmer with a standard 6-cable connection to a standard target board would always send the m328 into reset making it an SPI periphery for in system programming of the m328 no matter what AVRDUDE does.
If the project really wants to use SPI communication between the AVRISPmkII programmer and the boards's m328 then the m328's firmware would, out of necessity, operate in periphery mode as the programmer expects to drive SPI in host mode. This implies that the m328's SPI select pin PB2 should be connected to the 6-pin ISP connector instead of the m328's reset pin. This in turn requires a hard…