Building a dual MCU project with two ATmega328 chips

I've been thinking about having a project with dual '328 MCU and using I2C for comm between the two. I did some Google searching and found this blog, where the builder made a shield with a second '328. My objective is to have a lot of I/O pins.

Does the above tutorial look like the best way to approach such a project? Maybe I should build a single MCU project with a more powerful MCU, like an Arduino Mega?

Thanks,
Jake

It can be very convenient to use several microcontrollers in one project. For example, certain manufacturers sell LED displays with an ATmega328 as a display controller. I built a project with several of these displays plus an Arduino, in effect making a 5 "core" device.

In another project I built the Arduino has to handle two simultaneous tasks: a user interface (via encoders, buttons, IR, and LED displays) plus some timed loops running in parallel. I had to write some fairly complicated code to ensure the interface is responsive without affecting the accuracy of the timers. With hindsight the project would have been a lot easier with two Arduinos.

The communication method you use isn't important: it can be serial, I2C, SPI, or simple signalling via digital I/Os.

A more powerful chip can certainly reduce the need for multiple microcontrollers, but it's not necessarily an easier or even a cheaper solution.

Or use a '1284. 32 IO, 2 UARTs, more SRAM than a 2560, still available as a DIP.
See my signature link for some examples.

Or, add a bunch of shift registers to a '328. I think the last picture at my link is a board with 12 shift registers. 96 higher current, high voltage capable Outputs.

Some of the more complicated projects I have in mind would benefit enormously from having a dual-MCU setup. I think it's a perfectly reasonable way of handling complex tasks if, like me, you lack the necessary coding skills to pull it off with a single high-end chip and aren't all that bothered about minimizing hardware costs for mass production :slight_smile: One such idea was for an 80s style drum synth, and while the current "solution" is to use one MCU for all input control scanning and display twiddling and a whole other one for sample playback, I am sure a decent programmer could do the whole thing on a single processor.

I suppose it depends what you're better at. If you're more comfortable with complex hardware than tricky code, then two Arduinos (or equivalent) might be a good way of approaching a problem.

Thank you for the feedback gentlemen. CrossRoads, absolutely incredible looking boards on the page linked to in your signature.

Since I have the parts already and am an absolute beginner at this, I think I'll start off by exploring communication between two '328 MCUs and work my way up from there; one on my Uno the other on a breadboard.

Adding the link to an excellent I2C tutorial for comm between 2 or more Arduinos:

http://www.uchobby.com/index.php/2008/09/16/introduction-to-i2c/

While it is a neat project, I wouldn't call it dual core, since the usual definition of dual core is two processors inside the same chip that share physical memory (and possibility caches, possibly not).

Yeah, I agree. I picked up the "dual core" term during my Google searching. I think I'll rename it "dual MCU."

Thanks Michael.

Here’s a dual '328 design I ruminated on a while back but never implemented.
I have a dual '1284 done up too.
I wouldn’t mind ordering a set of boards if there was some other interest.
About $4.50 a board to mail a single PCB out when they arrived.

I was also thinking about trying something like this only slightly different. Say have an Atiny 85 running/doing something as part of an entire assembly/sensor/module and having a pin or 2 output to a 328. Or have a 328 pin trigger the 85 to run some type of sketch.

Does this make any sense or does anyone see any big flaws with attempting this?

That would make sense if you are remoting the funtionality someplace I suppose. Put the processing at the sensor source, send the results back via RS485 interface. Or something.

CrossRoads:
Here's a dual '328 design I ruminated on a while back but never implemented.
I have a dual '1284 done up too.
I wouldn't mind ordering a set of boards if there was some other interest.
About $4.50 a board to mail a single PCB out when they arrived.

Very nice! You can count me in for one of the dual '328 pcb's if you have them made up. I might even take two :slight_smile:

PM or email if you do it.

Thanks,
Jake

Okay, I'll review the design and see it it needs any tweaking based on things I've done since Idid these.

Say have an Atiny 85 running/doing something as part of an entire assembly/sensor/module...does anyone see any big flaws with attempting this?

No problems with that. I helped a friend design a board with a Mega256 and 4 Tiny84s. The 84s handled high-speed frequency/period measuring and they all worked as SPI slaves to the Mega.


Rob

Allright, I've got 2 '328s breadboarded as minimal hardware setups.
Bootloaded both with Uno optiboot, get 3 quick flashes on reset, looking good.

I need to change the CKSEL fuses on one of them to 0000 so I supply it with an external clock (which I will provide from the other '328).

Was gonna do it with AVR ISP MKii, but AVR Studio 5 doesn't seem to recognize it as being plugged in, I am guessing as a result of changing from the AVR Studio default Jungo driver, to the Arduino provided driver for the MKii.

Is there a way to use avrdude or something to change the CKSEL fuses?

Off to bed now, will try any suggestions after work tomorrow.

Thanks!

Is it just the avrdude parameters you need? The following will set the fuses to the normal values for an Optiboot Uno (in this case using an ArduinoISP on COM6 as the programmer):

avrdude -c stk500v1 -p atmega328p -P com6 -b 19200 -u -U lfuse:w:0xff:m -U hfuse:w:0xde:m -U efuse:w:0xfd:m

The CKSEL bits are in the low fuse byte, so for an external clock (keeping 65ms startup time) I'd change that to

avrdude -c stk500v1 -p atmega328p -P com6 -b 19200 -u -U lfuse:w:0xe0:m -U hfuse:w:0xde:m -U efuse:w:0xfd:m

Hope that's helpful. How are you linking the clocks? Are you using CLKO or XTAL2 to drive the 2nd chip?

Yes, the avrdude command/parameters.

This part here changes the CKSEL bits? lfuse:w:0xe0:m
Why does the upper bit of 0xff get changed as well?

Low Fuse Byte Bit No Description Default Value
CKDIV8(4) 7 Divide clock by 8 0 (programmed)
CKOUT(3) 6 Clock output 1 (unprogrammed)
SUT1 5 Select start-up time 1 (unprogrammed)(1)
SUT0 4 Select start-up time 0 (programmed)(1)
CKSEL3 3 Select Clock source 0 (programmed)(2)
CKSEL2 2 Select Clock source 0 (programmed)(2)
CKSEL1 1 Select Clock source 1 (unprogrammed)(2)
CKSEL0 0 Select Clock source 0 (programmed)(2)

Note: 1. The default value of SUT1...0 results in maximum start-up time for the default clock source.
See Table 9-12 on page 34 for details.
2. The default setting of CKSEL3...0 results in internal RC Oscillator @ 8MHz. See Table 9-11 on
page 34 for details.
3. The CKOUT Fuse allows the system clock to be output on PORTB0. See ”Clock Output Buffer”
on page 36 for details.
4. See ”System Clock Prescaler” on page 36 for details.

So have bit 7 = 0 means Divide by 8 is enabled? I still want to run at 16 MHz.
The clock will be coming from Xtal2 on the 2nd 328 in the dual-328 system I am proofing out, and go into Xtal1.
PB0 will not be changed, and PB7 should be free'd up as well. I suppose that could be added to pins_arduinio.h as well to have another IO pin.

CrossRoads:
This part here changes the CKSEL bits? lfuse:w:0xe0:m
Why does the upper bit of 0xff get changed as well?

That's it. Zero = programmed, so the default lfuse value of 0x62 enables the clock divider and results in a 1MHz clock. Interestingly the clock prescaler can be overridden in software by writing to CLKPR. Handy for testing code on a 5V 16MHz board before building a project based on a lower-frequency board. It can also be used for power saving without the bother of entering and exiting sleep mode, although I haven't tried this myself.

Ok, so I really want
lfuse:w:0xf0:m
so it is Not programmed and Not divided down.
Will try it when I get home & see what happens.