Building a dual MCU project with two ATmega328 chips

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.

One protocol I have been very happy with is EasyTransfer by Bill Porter. Available as a I2C as well as Serial library. Makes communications between two Arduinos a snap. Used it for 2 328's, a 328 and a 1284p, etc. Highly recommended.

Erm, not quite sure I'm on the same wavelength. Are you mixing up bit 4 & 7? As far as I can make out 0xF0 is not an allowed combo.

0xE0 = 0b11100000 : CKDIV=1 (disabled), CKOUT=1 (disabled), SUT=10 (65ms startup), CKSEL=0000 (ext. clock)
0xF0 = 0b11110000 : CKDIV=1 (disabled), CKOUT=1 (disabled), SUT=11 (reserved), CKSEL=0000 (ext. clock)

@tim7, You are right - I was flipping the wrong bit of the nibble. 0xe0 it is.

@Constantin, Hadn't got that far yet. Still working on getting 2 uCs running of 1 crystal so I can some boards ordered. I think I have enough jumpers/headers on the board so any of those kinds of comm's can be set up.
See the schematic in Reply #9 of this thread. Have to tweak the crystal connections a little - xtal2 of chip1 will feed xtal1 of chip2. chip2 will have fuses set to allow external clock.
Think I'll do the connections with solder jumper pads so the two can be isolated if needed.

No worries. Just thought I'd chime in re: using the I2C bus for the communications. Pretty easy to implement and requires few traces and components on the board. Maybe give a choice using a shunt jumper or a cutable pad for SDA and SCL?

I'm following this thread with great interest. Would definitely like to try out a dual '328 board with I2C when it's ready.

I hope I don't get in over my head though! :smiley:

@Constantin - Check the schematic - I added internal headers so the two uC could talk to each other with user installed jumpers, while also keeping header pins free for offboard connections.

@BlueJakester - I'll order some boards once I verify the fuses & clock connections. Maybe tonight.

If I'm in a hurry I usually use this site:

http://www.engbedded.com/fusecalc

That gets the fuse bits right, and tells you the exact (partial) avrdude command -- the part with the fuses in it.

Ok, how do I run that?
Win Vista
Opened Command Prompt,
worked my way down to
C:\Arduino1.0\hardware\tools\avr\bin>
typed in this:
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

Get a couple of errors back:
avrdude: can't open config file "": Invalid argument
avrdude: error reading system wide configuration file ""

Probably add -C ..\etc\avrdude.conf to the options list... that's what I have to do

FWIW, I have this jotted down in my text notesfile for the 1284P:

(Burning Bobuino fuses on MacOS X)

bin/avrdude -C etc/avrdude.conf -v -p m1284p -c stk500v2 -P /dev/tty.usbmodem411 -e -Ulock:w:0x0F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xFF:m

Are the fuses programmed via ICSP or via the Serial interface?

ICSP. The serial interface is only for the bootloader.

Okay, I made a file called install_clock.bat with 1 line:

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

I moved it into the same directory with avrdude.exe

I went into Command Prompt mode - and I still can't get it to run. I get the same error as noted before about the config file.

Device Manager shows this for the AVR ISP MKii:
Port_#0001.Hub_#0006

It doesn't show up under the COM ports - so now I'm wondering what COM# should be in the command line.

Pain in the butt ....

I don't have an AVR ISP mkII to try, but I think the right configuration is this:

avrdude -c avrisp2 -p atmega328p -P usb -u -U lfuse:w:0xe0:m -U hfuse:w:0xde:m -U efuse:w:0xfd:m

Be aware that the -U commands may trigger an automatic erase of the flash memory. You can try adding the -D option to disable this, although I'm not sure whether it's actually possible to change the fuses without a flash-erase. The normal procedure for loading Optiboot and setting the fuses (adapted for external clock and AVR ISP mkII) goes like this:

avrdude -c avrisp2 -p atmega328p -P usb -e -u -U lock:w:0x3f:m -U lfuse:w:0xe0:m -U hfuse:w:0xde:m -U efuse:w:0xfd:m
avrdude -c avrisp2 -p atmega328p -P usb -U flash:w:optiboot_atmega328.hex -U lock:w:0x2f:m

BTW, I found it convenient to have WinAVR installed for this kind of thing. Amongst other things this installs a bunch of handy utilities and sets the windows path to find them. The upshot is that you can run avrdude from whichever directory is convenient, without worrying about setting the full path. It's a minor thing, but one I found handy.

Ok, the design is gonna add 30 cents and go with 2 crystals.
Getting the fuses set for anything other than what the IDE does while installing a bootloader is to complex.

Ok, I am calling it done.
Dual '328s, dual crystals, pins to connect Serial, I2C or SPI using D10 as Slave Select.

Unless some one sees some glaring omission or mistake, I'll order boards tomorrow.

No BAT54 diode on the reset lines?

I would also consider going for a single set of pull-ups for the I2C bus @ 2.2K or two sets of 4.7k units instead of 10K. Better chance of square waveforms in high speed mode.

HTH...

Ah, reset diodes. Good catch. When I started this way back, those hadn't been in use.
10Ks on I2c were arbitrary, I'll change to 4.7K.
User can install one or the other, or both if each uC will have its own I2C devices.

Ok, reset diodes have been added, artwork cleaned up, passes all design rule checks.
Boards are ordered.
Bare boards will be $5 mailed to US locations.