Pages: 1 [2] 3 4 ... 6   Go Down
Author Topic: Building a dual MCU project with two ATmega328 chips  (Read 9172 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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):

Code:
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

Code:
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?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: August 01, 2012, 09:23:43 am by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Peoples Republic of Cantabrigia
Offline Offline
God Member
*****
Karma: 6
Posts: 722
Arduino happiness
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Switzerland
Offline Offline
Sr. Member
****
Karma: 6
Posts: 375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
« Last Edit: August 01, 2012, 02:35:38 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Peoples Republic of Cantabrigia
Offline Offline
God Member
*****
Karma: 6
Posts: 722
Arduino happiness
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Colorado
Offline Offline
Full Member
***
Karma: 1
Posts: 170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-grin
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 495
Posts: 19039
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ""
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Maryland, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 162
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Code:
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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: 1 [2] 3 4 ... 6   Go Up
Jump to: