I want to run an atmega328 on a breadboard at 2MHz and upload to it via the serial pins (pins 2 and 3). So I am setting the clock divide by 8 fuse bit to enable this, meaning the atmega runs at 2MHz eith the 16MHz crystal. But I can't upload, probably because the bootloader is not expecting the clock to be running at 2MHz. The baud rates are probably mismatched by 8 times, the IDE is trying to upload at 57600 but since the bootloader code is not aware its being clocked at 2MHz, its probably running 8 times too slow. I've messed around a bit with the arduino conf files changing baud rates but had no joy. I was wondering if anyone knows how to do this off the top of their head.
Thanks, Pete
1 Answer 1
Unprogram the CKDIV8 fuse and add the following to the sketch instead, near the beginning:
#include <avr/power.h>
void setprescaler(void) __attribute__ ((naked)) \
__attribute__ ((section(".init1")));
void setprescaler(void)
{
clock_prescale_set(clock_div_8);
}
This will do essentially the same thing as the fuse, but won't interfere with the bootloader.
-
Is there not a risk to running the atmega out of its SOA even if only for a few cycles? I guess I could use that technique while working on the project and change to fuse divider for 'production' but I was wondering if theres either a setting in the IDE to modify the serial speed during upload, or a easy way to set the baud in the bootloader, even if it means recompiling it.Pete– Pete2015年09月08日 20:31:02 +00:00Commented Sep 8, 2015 at 20:31
-
What voltage are you running it at, 1.8V?Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2015年09月08日 20:33:12 +00:00Commented Sep 8, 2015 at 20:33
-
If you are running at 1.8V, I don't see how you can be using a serial upload, because the voltages will be too high. If you are running at 5V you can do what Ignacio Vazquez-Abrams suggested.2015年09月08日 22:01:32 +00:00Commented Sep 8, 2015 at 22:01
-
No I'm initially trying at 5v just to get it working before dropping to 3.6, the project has a SD card (currently unplugged) which determines the voltage. So I also have to work on it at 3.6 to avoid damage to the SD. I use the usbasp and today, I bricked 2 atmega328s. I only have one left until my next order turns up. What's happening is if I forget to switch the usbasp back to 5v before uploading, the fuses get set to 0, setting the reset pin to disable, bricking the chip. PITA.Pete– Pete2015年09月08日 22:11:46 +00:00Commented Sep 8, 2015 at 22:11
-
Don't know why this happens but it does (I get an error at the end of upload about fuse settings not matching, despite code upload apparently succeeding). Since I need 3.3v for SD I have to clock lower than 12MHz but only have 16MHz crystals hence divider bit. Plan is to use serial instead of USBASP to avoid fuse bits being touched during upload. All works fine if I disable clock divider, so problem is related to speed.Pete– Pete2015年09月08日 22:11:55 +00:00Commented Sep 8, 2015 at 22:11
Explore related questions
See similar questions with these tags.
avrisp
section. Replaceavrisp.
withavrispslow.
or something, and change the.name=AVR ISP
with.name=AVR ISP Slow
. Addavrispslow.speed=7200
andavrispslow.program.speed=7200
. Restart the IDE. You should now have a new item in theBoards
=>Programmers
menu.