Arduino using external clock and 1mhz

r55boy:
Sorry if this is just confusing things... ;-(

It is. You may be able to keep it all straight. I cannot. I suggest committing to one processor and one goal. Do not add more processors to the mix until you get something that works. Do not flip between a bootloader and ISP; pick one. (ISP is a better choice for a low power project).

Right mate - sorry. I have made a discovery - and its REALLY basic.

  1. I put a fresh bootloader onto chip using Optiloader.
  2. I load the BLINK sketch (using UNO 16MHz std board) - all fine
  3. I hit load again to load the sketch a second time - fails.

Some of the logs attached from avrdude (had to chop it to get it under 9500 bytes to post). So basically after a load a sketch to my chip, it wont take any more sketches, until i reburn the bootloader using optiloader.

Binary sketch size: 1018 bytes (of a 32256 byte maximum)
C:\arduino-0022\hardware/tools/avr/bin/avrdude -CC:\arduino-0022\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cstk500v1 -P\\.\COM5 -b115200 -D -Uflash:w:C:\Users\Sean\AppData\Local\Temp\build4803119672540980343.tmp\Blink.cpp.hex:i 

avrdude: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "C:\arduino-0022\hardware/tools/avr/etc/avrdude.conf"

         Using Port            : \\.\COM5
         Using Programmer      : stk500v1
         Overriding Baud Rate  : 115200
avrdude: ser_open(): setting dtr
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: 
avrdude: Recv: 
         AVR Part              : ATMEGA328P
         Chip Erase delay      : 9000 us
         PAGEL                 : PD7
         BS2                   : PC2
         RESET disposition     : dedicated
         RETRY pulse           : SCK
         serial program mode   : yes
         parallel program mode : yes
         Timeout               : 200
         StabDelay             : 100
         CmdexeDelay           : 25
         SyncLoops             : 32
         ByteDelay             : 0
         PollIndex             : 3
         PollValue             : 0x53
         Memory Detail         :

 avrdude: verifying ...
avrdude: 1018 bytes of flash verified
avrdude: Send: Q [51]   [20] 
avrdude: Recv: 
avrdude: Recv: 

avrdude done.  Thank you.

##############

Then i press UPLOAD again:

Binary sketch size: 1018 bytes (of a 32256 byte maximum)
C:\arduino-0022\hardware/tools/avr/bin/avrdude -CC:\arduino-0022\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cstk500v1 -P\\.\COM5 -b115200 -D -Uflash:w:C:\Users\Sean\AppData\Local\Temp\build6732692812831451024.tmp\Blink.cpp.hex:i 

avrdude: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "C:\arduino-0022\hardware/tools/avr/etc/avrdude.conf"

         Using Port            : \\.\COM5
         Using Programmer      : stk500v1
         Overriding Baud Rate  : 115200
avrdude: ser_open(): setting dtr
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: 
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: Send: Q [51]   [20] 
avrdude: Recv: 
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

avrdude done.  Thank you.

You know these chips ship with internal clock set up as 8 MHz / 8 = 1 MHz?
Just saying, if you want 1 MHz then why bother with external clock at all unless you want precise?

And I wonder, from what I see on the pin map if you don't use external crystal then all 8 PORTB pins should be open for use?

  1. I put a fresh bootloader onto chip using Optiloader.

Using the latest version of OptiLoader?

  1. I load the BLINK sketch (using UNO 16MHz std board) - all fine

Just so I'm clear... You upload OptiLoader to your Uno, run OptiLoader to install a bootloader to a processor on a breadboard, move the breadboard processor to your Uno for testing. Correct?

  1. I hit load again to load the sketch a second time - fails.

That indicates the lock-bits were not correctly set.

If it's going to run on an UNO, doesn't it have to be set for 16 MHz clock?

Actually, it doesn't. But the baud rate has to be adjusted (divided by 2 or 16) -or- a bootloader configured for the slower clock has to be installed.

In any case, I assume the end-goal is ISP uploads and that the with-bootloader attempt is a way-point.

It may also be worth looking at this webpage on low power setup of Atmega chips.

http://www.sparkfun.com/tutorials/309

It has some good tips and extra powersaving features not discussed in this thread.

lemming - thx for the link - will spend some time digesting that.

Coding - i think u are bang on - i think i have screwed up the lock fuse - i changed the code in optiloader to get it to set my fuses after programming to my desired values - in the code below I changed the 0x2f,0,0,0,0 to 0x2f, Lowfuse, Highfuse, Efuse, 0.

I strongly suspect that this is not correct and need to find how to do this, for now i will set it back to 0x2f,0,0,0,0 and try again when i get home...

"atmega328P" }
,
0x950F, /* Signature bytes for 328P */
{
0x3F,0xFF,0xDE,0x05,0 }
,
{
0x2F,0,0,0,0 }

Why do you want to use a bootloader?

I am used to using "upload sketch" but dont want bootloader specifically for sure - more than happy and hoping to use your suggestion provided previously. I was only looking at bootloaders as i was trying to change fuse settings to set up the CKDIV8 and Brownout disable. Wow - it seems like weeks ago i set out to achieve something seemingly so simple!! :~

Been working this problem some more and i think the problem is baud rate.

Remember that optiloader works to my target board, but burning bootloader from within the Arduino environment doesnt, and neither does using your atmega328Pbb boards.txt file boards.

The error is:-

Binary sketch size: 1042 bytes (of a 32768 byte maximum)
C:\arduino-0022\hardware/tools/avr/bin/avrdude -CC:\arduino-0022\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cstk500v1 -P\\.\COM5 -b9600 -Uflash:w:C:\Users\Sean\AppData\Local\Temp\build5032370817224311009.tmp\Blink.cpp.hex:i 

avrdude: Version 5.4-arduino, compiled on Oct 11 2007 at 19:12:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         System wide configuration file is "C:\arduino-0022\hardware/tools/avr/etc/avrdude.conf"

         Using Port            : \\.\COM5
         Using Programmer      : stk500v1
         Overriding Baud Rate  : 9600
avrdude: ser_open(): setting dtr
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: 
avrdude: stk500_getsync(): not in sync: resp=0xff
avrdude: Send: Q [51]   [20] 
avrdude: Recv: 
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0xff

avrdude done.  Thank you.

So - i tried the command line, and get the same problem until i switch to baudrate of 19200. then it works:

C:\arduino-0022>avrdude -p m328p -P com5 -c avrisp -b 19200

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.13s

avrdude: Device signature = 0x1e950f

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

So - how do i force the baudrate to 19200 instead of the 9600 that the arduino environment is using? Does this make sense?

By the way - the port is set to 19200 baud in control panel.

This is definitely it! I intercepted the command being generated and updated the baud rate in there from 9600 to 19200, see below, and IT WORKED!!! So how to i make the IDE use a baud rate of 19200 when generating these command lines?

C:\arduino-0022\hardware/tools/avr/bin/avrdude -CC:\arduino-0022\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -cstk500v1 -P\\.\COM5 -b19200 -Uflash:w:C:\Users\Sean\AppData\Local\Temp\build3447786868117704274.tmp\Blink.cpp.hex:i

My boards.txt is below and contains the 19200 baud.

atmega328Pbb0.name=ATmega328P @ 1 MHz  (external oscillator; BOD level1)

atmega328Pbb0.upload.using=arduino:arduinoisp
atmega328Pbb0.upload.maximum_size=32768
atmega328Pbb0.upload.speed=19200
atmega328Pbb0.bootloader.low_fuses=0x4c
atmega328Pbb0.bootloader.high_fuses=0xD7
atmega328Pbb0.bootloader.extended_fuses=0xfe
atmega328Pbb0.bootloader.path=empty
atmega328Pbb0.bootloader.file=empty328Pat1.hex
atmega328Pbb0.build.mcu=atmega328p
atmega328Pbb0.build.f_cpu=1000000L
atmega328Pbb0.build.core=arduino:arduino
atmega328Pbb0.build.variant=arduino:standard

atmega328Pbb0.name=ATmega328P @ 1 MHz (external oscillator; BOD level1)
atmega328Pbb0.upload.protocol=arduino
atmega328Pbb0.upload.maximum_size=32256
atmega328Pbb0.upload.speed=19200
atmega328Pbb0.bootloader.low_fuses=0x4c
atmega328Pbb0.bootloader.high_fuses=0xD7
atmega328Pbb0.bootloader.extended_fuses=0xfe
atmega328Pbb0.bootloader.path=empty
atmega328Pbb0.bootloader.file=empty328Pat1.hex
atmega328Pbb0.build.mcu=atmega328p
atmega328Pbb0.build.f_cpu=1000000L
atmega328Pbb0.build.core=arduino:arduino
atmega328Pbb0.build.variant=arduino:standard

Coding - with these change to boards.txt i get error "avrdude: Can't find programmer id "arduino".

i have uploaded ArduinoISP to my programmer board and have it hooked up to the target on a breadboard.

My problem is just now that the Arduino environment seems to be setting the avrdude -b parameter to 9600 when it should be 19200 and i cant see why. when i manually invoke avrdude and use -b 19200 it works.

thanks again for your help on this mate.

Remove this line from your boards.txt file...

atmega328Pbb0.upload.using=arduino:arduinoisp

Coding - i dont have that line in there - just the lines in your posting below. i guess its the upload.protocol it doesnt like ?

Boards.txt below. Remember my only problem now is just the baud rate it is insisting on using...

Thanks...

atmega328Pbb0.name=ATmega328P @ 1 MHz  (external oscillator; BOD level1)

#atmega328Pbb0.upload.using=arduino:arduinoisp
atmega328Pbb0.upload.protocol=arduino
#atmega328Pbb0.upload.maximum_size=32768
atmega328Pbb0.upload.maximum_size=32256
atmega328Pbb0.upload.speed=19200
atmega328Pbb0.bootloader.low_fuses=0x4c
atmega328Pbb0.bootloader.high_fuses=0xD7
atmega328Pbb0.bootloader.extended_fuses=0xfe
atmega328Pbb0.bootloader.path=empty
atmega328Pbb0.bootloader.file=empty328Pat1.hex
atmega328Pbb0.build.mcu=atmega328p
atmega328Pbb0.build.f_cpu=1000000L
atmega328Pbb0.build.core=arduino:arduino
atmega328Pbb0.build.variant=arduino:standard

Guys any idea here? All seems correct, and Coding Badly has this working, but no joy for me. I've been tearing my hair out for a month now, and certainly know so much more about boards.txt etc etc, but fail with the baud rate that it insists on using, despite me telling it otherwise. Arghhhh!

Thanks for any steers...

I can't be sure but you could try to back up your boards.txt and actually remove the lines you have commented out.

If everything else is correct (e.g. the entry in boards.txt) the baud rate is defined in the programmers.txt file...

arduinoisp.name=Arduino as ISP
arduinoisp.communication=serial
arduinoisp.protocol=stk500v1
arduinoisp.speed=19200