Go Down

Topic: ATMega328P sketch error (Read 1 time) previous topic - next topic

fbriggs4

I am new to all of this so please bear with me. I am bread boarding a 328P and I need to run an 8mhz internal clock. I am using a sparkfun AVR pocket programmer. I followed this tutorial which worked well.

http://arduino.cc/en/Tutorial/ArduinoToBreadboard

I first loaded a 16mhz external bootloader which worked well and I could load sketch's with no issue. After following that tutorial I loaded the breadboard internal 8mhz bootloader through the Arduino IDE and then tried to load my sketch. I tried several sketch's and they all seem to load and run without any issue however I get the following error:

avrdude: stk500_paged_load(): (a) protocol error, expect=0x14, resp=0x88
avrdude: stk500_cmd(): protocol error

Since everything is working I am tempted to keep going and ignore the error but that would likely bite me down the road so I am hoping it is something silly that can be easily corrected.

I have seen the following post which has a similiar issue but he can not load the sketch at all and I can despite the error.

http://arduino.cc/forum/index.php/topic,59721.0.html

The suggestion was to alter the high fuse if you followed the Arduino tutorial like I did. However my fuse setting are different so I am hesitant to change mine since I don't completely understand them. My board file settings are listed below:

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

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=stk500
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.path=arduino:atmega
atmega328bb.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino


any suggestions are greatly appreciated!


Coding Badly


Why do you want to use the internal oscillator?  You can get crystal + capacitors for $2 ... http://evilmadscience.com/productsmenu/partsmenu/144-xtlcaps

CrossRoads

Another source:

xtal http://www.dipmicro.com/store/XC7-16000  32 cents
22 pf caps http://www.dipmicro.com/store/C1K22-1000 14 cents each
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

fbriggs4

My application requires the use of a small battery and in order to preserve the battery I have to get the consumption as low as possible. My goal is to use the internal 8mhz clock for running the sketch while awake and then put the AVR to sleep  and run timer2 with a 32.768 khz crystal when sleeping which should get me down to 1uA. Any ideas how or why I would get those errors when I load the sketch?

Coding Badly

My application requires the use of a small battery


Got it.

run timer2 with a 32.768 khz crystal when sleeping which should get me down to 1uA


I believe 1uA is only possible with everything powered down.  I vaguely recall that running timer2 with a watch crystal uses several microamps.

Quote
Any ideas how or why I would get those errors when I load the sketch?


Post the verbose output from uploading.  Hold the shift key when you click Upload.

Udo Klein

Everything powered down but still listening to level interrupts can get you down to <1uA. However this means EVERYTHING. It is not enough to just stop the crystal. Especially the AD converter must be explicitly stopped. In addition it is a good idea to prescale down to 1 MHz because this will lower the acceptable voltage thus reducing the power consumption further. Lowering any further does not help because the frequency does not matter during sleep. (Because the oscillator is stopped). While awake it will lower current consumption but at the price of running longer. Since the oscillator may dominate power consumption I think the best approach is to lower frequency to the point where you can not decrease voltage any further. From that on do not lower it anymore.

You can also run from the 128kHz WDT but this does not offer much of an improvement. Prescaling the WDT is possible but does not help either.

Also you must avoid floating pins. Floating pins will increase the power consumption.

This leaves the question how to get 32kHz in a most power efficient way. My finding is that you can not beat a RTC chip both for power consumption and precision.

This in turn raises the interesting question what would happen if you use the RTC to feed the processor with a 32kHz external clock. I never tried this but my gut feeling would be that this would actually increase power consumption. But you would have to try this to find out.
Check out my experiments http://blog.blinkenlight.net

fbriggs4

@ Udo, Thanks for the suggestions. For my application it is not a problem to power down everything. I am using timer2 and interupts to wake it up so everything can be shut down.

I attached verbose output. I think the issue is that it is looking for an STK500V1 and I am using an AVR pocket Programmer from Sparkfun. Should I change the programmer in the board file? If so what should I list?

Thanks for all the help everyone, it is really appreciated!

Coding Badly


From the factory, the internal oscillator is ±10%.  Anything past ±4.5% is going to cause problems with serial communications.  I suspect the oscillator is right at the fringe of being able to support serial communications.

Have you tried to tune the internal oscillator?

fbriggs4

I wanted to give an update since I was finally able to resolve the problem. Although I am using capacitors it seems they were not close enough to the AVR. Once I put the caps closer to the ATMega328P I could load a sketch using the 8MHz internal clock with no errors. Thanks again to everyone who had suggestions for me!

Coding Badly


Bypass (0.1 uF) capacitors?

fbriggs4

I had both 10uF and 0.1uF when I was getting the errors. At the moment I have the 0.1uF caps removed and just run the 10uF cap right next to VCC which solved the problem. I know I should have the bypass caps but I didn't have time to play with putting the 0.1uF cap back and see if that causes the error again. Most likely it will work with the bypass caps and the issue was the 10uF being a bit to far from VCC.

Coding Badly


What else is in the circuit?

Does the problem occur when the target is powered via USB?  Battery?

fbriggs4

To load the sketch I am using a Sparkfun FT232 USB break out board which supplies 3.3V. I never tried to load a sketch while powering the board with the lipo. When I run the sketch I use a 3.7V lipo unregulated. To isolate the issue I had the bread board stripped down to nothing but the ATMega328, a 10uF cap, a couple of decoupling caps and a 10k resistor on the reset line. Literally nothing else was on the board, not even an LED. I am attempting to get the AVR to sleep at 1uA (unsuccessfully) and I was pulling caps when it was running to see if it had any impact. When I put the 10 uF cap back I figured it should be closer to VCC so I moved it. After that I could load a sketch with no errors. I had the 10 uF next to AVCC and apparently it did not like that. No other changes to the bread board or sketch were made so I am pretty sure it was moving the cap closer to VCC that did it.


Coding Badly

I am attempting to get the AVR to sleep at 1uA (unsuccessfully)


To get to that level, you have to shut off EVERYTHING.  The CPU clock.  The Brown Out Detector.  The Analog to Digital Converter.  Everything.  And no floating pins.

Quote
No other changes to the bread board or sketch were made so I am pretty sure it was moving the cap closer to VCC that did it.


Huh.  I'm glad you found the solution.  It certainly would have stumped me.

Go Up