Cannot program Mega328P-PU after switch to internal oscillator

Very new to Arduino ecosystem, so sorry if this is a dumb question...

I'm Using a stand-along ATMEGA328P-PU DIP on a breadboard for a lighting control application. My "Board" in the Arduino IDE is set to "Arduino Uno", since that board uses the same chip (328P-PU). My chips are all programmed with the Arduino bootloader

I've been happily running with a 16Mhz crystal for a while now at various clock rates using the pre-scaler. Now that Im loooking to make boards, I want to simplify the external circuitry and use the 8mhz internal oscillator.

I programmed the appropriate fuse using avrdude and my UNO as ISP (FUSE_LOW = 0xE2), verified it was programmed to the correct value, put the chip back on my breadboard, and removed the crystal and 22pf caps.

The chip is running my app as expected at ~8mhz, however I cannot program it with my FTDI adaptor, nor in the UNO.

I scoured the internet looking for information on this, but coudln't find any consistent advice. Some people say you need another bootloader, some say the original Arduino boorloader should work.

Do I need another bootloader?

Thanks, Steve

The CPU clock has to be a minimum multiple of the programming speed. You probably need to reduce the programming speed. Turn on Verbose output during programming and you will see what clock speed is supplied to avrdude when the IDE attempts to program it. I think it's the -B option.

Thanks

Looks like it's trying to use 115200

"avrdude" "-CC:\Users\me\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf" -v -V -patmega328p -carduino "-PCOM16" -b115200 -D "-Uflash:w:C:\Users\me\AppData\Local\Temp\arduino-sketch-E21D91B4C2461695A0D7853B404AE841/score_nodec.ino.hex:i"

I don't see any option to change the upload speed in the IDE. Is there one? Suppose I could try using avrdude directly but I've not used that for uploading (only for fuse burning)

Of course you do need to specific the correct clock rate.

The internal oscillator is not very accurate, and it is possible that it is far enough off of 8 MHz that serial communications with the bootloader fail.

If that is the case, use an ISP programmer. This one is by far the best and most flexible I've ever used.

Did you just change the fuse setting without changing the bootloader? If so, the upload speed will be at 1/2 the normal baud rate, or 57600, because the baud rate is derived from the clock rate, and the bootloader code was compiled for 16MHz.

Did you change the boards.txt file so that the compiler knows the clock is running at 8MHz? If not, then any timing-related functions will take twice as long.

Changing the clock speed is much easier if you use MCUdude's MiniCore, it has options for various clock speeds, and pre-compiles bootloader files to match those speeds.

No, I didnt change the bootloader, which is for 16M

I've tried changing the baudrate to 57600 in boards.txt (verified by verbose output) but this doesn't work either. Could it be the the resonator is not accurate enough to hit 57600?

Update: I'm able to program the chip at 57600 if I put it back into the Uno, but not on my breadboard, for which I use the 6-pin FTDI programmer to program the chip). This setup (the FTDI) always worked fine with the `16Mhz crystal.

Is there something special about the Uno (which I though also used the same FTDI chip)??

Oddly, I'm able to use the Serial monitor at 57600 bps with the Breadboard/FTDI programmer, but still no luck programming.

I'll try programming the 8Mhz bootloader and see if that helps

Ok, now I've loaded an 8mhz bootloader (that I got from googling off the internet) and nothing at all works at any buad rate. God this is turning into a clusterf****

Is there any site with some officiality I can get these stupid bootloaders from, rather than relying on googling, where there are about 100000 articles, each one with it's own files and slightly different way of doing things?

Did you install miniCore as suggested by @david_2018 ? When you have done that, select the appropriate chip type and clock speed in the boards menu, burn bootloader and hopefully your problems will be gone.

"DId you try Minicore"

I was hoping to avoid yet another compilicated thing (I understand the fuse bits and know how to program them and bootliader) but gave in and instaslled it since I have no better ideas:

I was able to select options and burn the bootloader, but when I put the chip back into the Uno and tried to burn my program it (as I expected) failed. The log of the failed attempt is below. For God knows what reason, it seems to want to run at 38400 Baud now, and I have no idea how to change that.

I guess running a MEGA328P on an internal oscillator is just too much to ask maybe.

Sketch uses 6274 bytes (19%) of program storage space. Maximum is 32256 bytes.
Global variables use 489 bytes (23%) of dynamic memory, leaving 1559 bytes for local variables. Maximum is 2048 bytes.
"C:\Users\sgord\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino18/bin/avrdude" "-CC:\Users\sgord\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf" -v -V -patmega328p -carduino -PCOM13 -b38400 -D "-Uflash:w:C:\Users\sgord\AppData\Local\Temp\arduino-sketch-E21D91B4C2461695A0D7853B404AE841/score_nodec.ino.hex:i"

avrdude: Version 6.3-20201216
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

     System wide configuration file is "C:\Users\sgord\AppData\Local\Arduino15\packages\MiniCore\hardware\avr\2.1.3/avrdude.conf"

     Using Port                    : COM13
     Using Programmer              : arduino
     Overriding Baud Rate          : 38400

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x8c
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x84
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x8c
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x84
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xfc

avrdude done. Thank you.

Failed uploading: uploading error: exit status 1

If you have a ISP programmer (and you definitely have it because it required for loading the bootloader) - why do not upload sketches via ISP?
When I played with custom atmega with internal oscillator, I did not wasted a time for bootloders... using the ISP is more easy and convenient.

Do not worry about the upload speed of 38400, that is the correct baud rate for the minicore bootloader. You can run any baud rate you wish from the actual sketch.

Make sure you did not have "Tools > No bootloader" selected when you burned the bootloader, and had "Tools > Clock : Internal 8MHz", there is an option for external 8MHz.

No idea why the chip cannot be programmed on the breadboard, especially since it worked with the 16MHz crystal.