atmega328 on a Breadboard (8MHz internal clock)

I've bootloaded my atmega328P with the "atmega328 on a Breadboard (8MHz internal clock)" bootloader but when i try to upload a sketch I get the error:

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

I'm using the AVR Pocket Programmer from sparkfun and I know it works because the atmega328p wasnt working before I reburnt the UNO bootloader onto it and now it works fine. But no luck with any other bootloader.

On a semi related note, does PWM work the same at 8MHz? I wanted to skip the external crystal because Im makeing a very simple fading LED device but obviously I may have to re-think it if PWM isn't effective at 8MHz.

ALSO the program isn't terribly time sensitive so accuracy isn't an issue, but does my sketch have to be changed to account for the clock speed change or is that accounted for by the bootloader so that millis() and delay() still act mostly the same?

Thanks!

For sketch loading the serial baud rate has to be right - if the internal clock isn’t accurate enough this could be an issue??

stoopkid: I've bootloaded my atmega328P with the "atmega328 on a Breadboard (8MHz internal clock)" bootloader but when i try to upload a sketch I get the error:

Did you use the IDE to burn the bootloader or did you do it through the command-line?

On a semi related note, does PWM work the same at 8MHz?

No. It runs at half the frequency. For most applications, you will not notice a difference.

I wanted to skip the external crystal because Im makeing a very simple fading LED device but obviously I may have to re-think it if PWM isn't effective at 8MHz.

For fading LEDs, you will not notice a difference.

ALSO the program isn't terribly time sensitive so accuracy isn't an issue, but does my sketch have to be changed to account for the clock speed change

So long as the entry in "boards.txt" is correct, you only need to build your Sketch.

I used the IDE. Is that a mistake? I'm not currently around my computer.

stoopkid:
I used the IDE. Is that a mistake?

No. That’s a good choice. The IDE takes care of the fuses and the bootloader.

But it also means the fuses are very likely correct so something else must be wrong.

Could it be that I’m using the 328p and not the 328?

Also I’m using the UNO and the UNO bootloader is the only one that works. Does that mean anything?

Are these the instructions you used... http://arduino.cc/en/Tutorial/ArduinoToBreadboard

Was this the "boards.txt" you used... http://arduino.cc/en/uploads/Tutorial/breadboard.zip

If "yes" to both questions, then the fuse settings are wrong. Open the "boards.txt" file and change this line...

  atmega328bb.bootloader.high_fuses=0xD9

...to this...

  atmega328bb.bootloader.high_fuses=0xD[glow=yellow,2,300]8[/glow]

(deleted)

I had the same problem the only difference is that I am using the duemilanove to burn the bootloader and upload the sketches. After reading this thread I finally figured out my problem. For the ATmega328p spycatcher2k's txt worked after putting it into the right location. His txt needs to be appended to the \arduino-00xx\hardware\arduino\boards.txt. The arduino IDE [u]MUST[/u] be restarted each time you edit the board.txt. I had used his settings before however never knew that the IDE needs a restart before changes take effect. Only when I fat fingered Coding Badly's fuse edit to read 0xD98 did i realize that the board file is only read when the IDE starts. No matter how many times I edited the boards file to fix my mistake until I restarted the IDE the changes would not take effect. Hope this helps someone avoid my mistakes of the last 12 hours.

Could this be why I too get the dreaded "avrdude: stk500_getsync(): not in sync: resp=0x00 avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51 Pro Mini" when using the "Pro Mini (3.3V, 8 MHz) w/ ATmega328" with a mega328P chip fitted?

Yours Simon M.

[quote author=Coding Badly link=topic=59721.msg430567#msg430567 date=1304015600]

stoopkid: I used the IDE. Is that a mistake?

No. That's a good choice. The IDE takes care of the [u]fuses[/u] and the bootloader.

But it also means the fuses are very likely correct so something else must be wrong.

[/quote]

I need to "re-bootload" some 328Ps that I bought, which are configured to run at 16Mhz/5V.

I need to change the bootloader so I can run the 328s at 8Mhz/3.3v. Is there a "clear" procedure on how to do this? Where do I get the modified bootloader from?

thanks

Do you actually want to install a bootloader on those chips (in which case you'll need to have some sort of serial interface in order to use it), or do you just want to load a program on to them? Or, do you already have the program loaded, and you just want to change them to run at 8MHz using the internal clock?

dc42: Do you actually want to install a bootloader on those chips (in which case you'll need to have some sort of serial interface in order to use it), or do you just want to load a program on to them? Or, do you already have the program loaded, and you just want to change them to run at 8MHz using the internal clock?

I bought a handful of these when they were on sale http://www.spikenzielabs.com/Catalog/index.php?main_page=product_info&products_id=160

I was told that I need to re-program the bootloader so the 328's will run at 8Mhz. I will be running these @ 3.3V in order to match the logic levels of the hardware I'm interfacing with. The 328 data sheet shows that 16Mhz @ 3.3V is not in "the safe zone", so I'm choosing to lower the clock to 8Mhz. For my application, speed isn't terribly important.

Obviously, I need to replace the 16MHZ crystal with an 8Mhz crystal, that is no problem.

Thanks

The bootloader will very likely work at half the clock speed. The latest optiboot does. Try halving the baud rate entry in the boards.txt file.

I am trying to use an atmega 328 with 8MHz internal clock with an IR LED that triggers a camera shutter. I have uploaded the sketch but it does not trigger the shutter. It works on my UNO. Could this be caused by the lower clock speed?

Thanks

I have uploaded the sketch

This one?

Or that one?

I uploaded the sketch to the UNO and it works. But when I upload it to the atmega 328 on a breadboard (with 8MHz internal clock), the camera does not fire.

Here is the sketch

#define irLED 12 
#define SWITCH 7

unsigned int pulseDuration = 10; //microseconds 
//The required 15 microseconds pulseDuration didn't work since digitalWrite consumes some additional time
//thats adds to pulseDuration value. 10 to 12 microseconds worked for me.

unsigned int photo = 7330; //A 7330 microseconds delay between bursts shoots a photo.
unsigned int video = 5360; //A 5360 microseconds delay between bursts starts/stops video recording. 

void setup() {
pinMode(irLED, OUTPUT);
pinMode(SWITCH, INPUT);
digitalWrite(SWITCH, HIGH); //turn on internal 20 k pullup resistor so the open input state is HIGH.
}

void loop() { //run again and again 
if (digitalRead(SWITCH) == LOW) { //read switch input
shoot(photo);
delay(1000);
}
}

void shoot(unsigned int delayBetweenBursts) { //sends the IR signal

//send first 16 bursts
for(int i=0; i<16; i++) { 
digitalWrite(irLED, HIGH);
delayMicroseconds(pulseDuration);
digitalWrite(irLED, LOW);
delayMicroseconds(pulseDuration);
} 

delayMicroseconds(delayBetweenBursts); 

//send second 16 bursts
for(int i=0; i<16; i++) { 
digitalWrite(irLED, HIGH);
delayMicroseconds(pulseDuration);
digitalWrite(irLED, LOW);
delayMicroseconds(pulseDuration);
} 

return;
}

Keep in mind that the Uno has a 328P on it, which is not the same as a 328. I didn't pay attention to that once and had to re-order the right ICs. Most, if not all, of the Arduino products that have a 328 on them are the 'P' variant (or Pico for lower voltage). So while you may have been able to burn the bootloader, burning sketches might be more problematic. At least, I couldn't, even after making sure the settings were correct for the non-P version.

The other piece that bit me was that Mouser has two versions of the 328P, a 10MHz and a 20MHz. As it turns out, you need that external oscillator hooked up to even be able to burn a bootloader. For the 20MHz one, I was able to run it with a 16MHz oscillator and burn a Pro Mini 3.3V/8MHz bootloader just fine. Once done, replace the oscillator for an 8MHz one. Or, if you're using the breadboard bootloader, simply remove the oscillator when you're done burning it. I thought I had defective chips when I got them, till I decided to try hooking up an oscillator. Suddenly everything made sense.

To make things easier, I burned my desired bootloader onto the IC (in the end I opted for the Pro Mini 5V/16MHz), then wired up the proper pins and used my FTDI to upload sketches. This meant I no longer needed my Uno to constantly be in ArduinoISP mode. It's only used to burn the bootloader onto new ICs. Now I can write code, send it to my Uno see if it works. Once verified, switch boards and com ports, and send it to another 328P, either on a breadboard, or a custom designed circuit. No need to reconfigure the Uno.

I have the exact same chip that comes with the UNO. It is an ATMEGA 328P-PU. I have burned the boot loader and it succeeded. I can upload the blink sketch and it operates fine. The only thing I can’t get to work is the sketch I posted above. I looked at the IR LED through a digital camera to make sure it was lighting up and it does. I am wondering if the reason it can’t trigger the camera is because of the clock speed being 1/2 of the clock speed on the UNO (which it works on).

Just out of curiosity, move the breadboard with the IR LED on it closer to the camera ... See what happens.