Serial does not work with internal 8Mhz oscillator [SOLVED]

I altered the fuse bits on a couple of ATMega8 chips so internal 8Mhz oscillator is used instead of external 16Mhz one and flashed a 8Mhz compatible bootloader. The chips work and I can upload sketches (and they run) ok using FTDI so the serial port works but the Serial commands don't work. Is this a known problem, have I missed something & is there a workaround please.

Below are the board.txt entry I added and used

atmega8.name=ATmega8-noxtal @8MHz

atmega8.upload.protocol=arduino
atmega8.upload.maximum_size=7168
atmega8.upload.speed=38400

atmega8.bootloader.low_fuses=0xe4
atmega8.bootloader.high_fuses=0xc2
atmega8.bootloader.path=atmega8_noxtal
atmega8.bootloader.file=ATmegaBOOT.hex
atmega8.bootloader.unlock_bits=0x3F
atmega8.bootloader.lock_bits=0x0F

atmega8.build.mcu=atmega8
atmega8.build.f_cpu=8000000L
atmega8.build.core=arduino
atmega8.build.variant=standard

Since the internal RC oscillator is not as well regulated as one using an external resonator or crystal you may have to use a slower baud rate to make sure the bit times fall within spec. Maybe re-compile your bootloader for 9600 baud.

Hi John,

Sketches upload without problem. I assume the 'atmega8.upload.speed=38400' is the speed for uploading but when I add a Serial.begin(9600) and subsequent Serial.print() commands nothing shows on the serial monitor (set to 9600). Maybe the problem is partly the bootloader but I have zero idea where to edit it and how to re-compile it. I just downloaded it from a link supplied on the forum somewhere.
I have just packed it all away ready to go home from work but tomorrow at home I will do some checks to see if the Serial crashes the ATMega or it just fails to send Serial data.

I have an Atmega8 bootloader made for 8 Mhz internal oscillator and 9600 baud. It’s attached to this post.
It’s built from the AtmegaBOOT source files included with Arduino 1.0
For me, sending serial over FTDI works fine at 9600 baud using this bootloader.

This is what I put in boards.txt

atmega8_8mhz_int.name=ATmega8 (8MHz internal OSC)

atmega8_8mhz_int.upload.protocol=arduino
atmega8_8mhz_int.upload.maximum_size=7168
atmega8_8mhz_int.upload.speed=9600

atmega8_8mhz_int.bootloader.low_fuses=0xc4
atmega8_8mhz_int.bootloader.high_fuses=0xca
atmega8_8mhz_int.bootloader.path=atmega8_8mhz
atmega8_8mhz_int.bootloader.file=atmega8_8mhz.hex
atmega8_8mhz_int.bootloader.unlock_bits=0x3f
atmega8_8mhz_int.bootloader.lock_bits=0x0F

atmega8_8mhz_int.build.mcu=atmega8
atmega8_8mhz_int.build.f_cpu=8000000L
atmega8_8mhz_int.build.core=arduino
atmega8_8mhz_int.build.variant=standard

atmega8_8mhz.hex (2.84 KB)

[quote author=Riva link=topic=116404.msg876296#msg876296 date=1343581150]
Sketches upload without problem. I assume the 'atmega8.upload.speed=38400' is the speed for uploading but when I add a Serial.begin(9600) and subsequent Serial.print() commands nothing shows on the serial monitor (set to 9600).

Oops. I misunderstood. Ignore my references to the bootloader.

Hmmm. Uploading uses the same serial I/O as Serial.print() so the hardware is good. Maybe that particular baud rate is out of spec. Try 38400 which we're pretty sure works.

Thanks perhof for the for the bootloader but I can upload sketches fine at 38400 with my current bootloader. I did notice you use different fuse bit settings but I can see no reason EESAVE & SUT1 would cause this problem.

Now I have some LED’s on the board (via a WS2803) I can debug with, it looks like the problem may be hardware related. It seems that after uploading a sketch the MPU does not always start/or delays a long time before starting. I am hoping this is due to me forgetting to ground the RX pins via a 10K resistor and the bootloader not letting go due to line noise of floating pin.
When the MPU does start then 9600 works fine.

I have also noticed that it takes a long time for the ATmega8 to start the sketch. Don't know why.

perhof:
I have also noticed that it takes a long time for the ATmega8 to start the sketch. Don't know why.

I seem to remember reading somewhere that older bootloaders can take several seconds after a reset to determine no sketch is going to be uploaded and pass control on, this with my floating RX pin is hopefully the problem.

In case you’re interested…
Here’s an optiboot bootloader that I just compiled for the ATmega8 with 8MHz internal OSC. It’s built from the optiboot source in the Arduino 1.0 package.
I haven’t tested it extensively but it seems to be running at correct speed, serial upload and serial communication over FTDI seems to work.
The delay before the sketch starts is completely gone and there is another 512k flash free compared to the old bootloader.

Boards:

atmega8_opti_8mhz.name=ATmega8 Optiboot (8MHz internal OSC)
atmega8_opti_8mhz.upload.protocol=arduino
atmega8_opti_8mhz.upload.maximum_size=7680
atmega8_opti_8mhz.upload.speed=115200
atmega8_opti_8mhz.bootloader.low_fuses=0xa4
atmega8_opti_8mhz.bootloader.high_fuses=0xcc
atmega8_opti_8mhz.bootloader.path=optiboot
atmega8_opti_8mhz.bootloader.file=optiboot_atmega8_8.hex
atmega8_opti_8mhz.bootloader.unlock_bits=0x3F
atmega8_opti_8mhz.bootloader.lock_bits=0x0F
atmega8_opti_8mhz.build.mcu=atmega8
atmega8_opti_8mhz.build.f_cpu=8000000L
atmega8_opti_8mhz.build.core=arduino
atmega8_opti_8mhz.build.variant=standard

optiboot_atmega8_8.hex (1.44 KB)

Thanks perhof,

When I next get some free time to breadboard my Mega8 for ArduinoISP programming I will give it a try. Does ArduinoISP also set fuses or do I have to set them some other way?

I don't know about ArduinoISP, I'm using a USBtiny, but I guess it should set the fuses.

Riva:
Does ArduinoISP also set fuses ...

Yes.

[quote author=Coding Badly link=topic=116404.msg879340#msg879340 date=1343839907]

Riva:
Does ArduinoISP also set fuses ...

Yes.[/quote]
Thanks, when I get time I will pop the chips and update the bootloaders.

When you compiled and uploaded your code was the board def set to something with a 16mhz clock by chance?

SparkysWidgets:
When you compiled and uploaded your code was the board def set to something with a 16mhz clock by chance?

Not sure if this is for me or perhof but my problem with serial not working was impatience on my behalf as the bootloader I used seems to wait for about 8 seconds before releasing control to the program. I though it may be because I had left RX & TX floating but it seems the bootloader is old and designed for manual reset (hence the long delay) where newer bootloader account for auto reset using the DTR signal. Serial worked all along, it's just I never waited long enough to see it after uploading a sketch. By putting some LED's on the board to use for diagnostics I realized there was a long delay between upload and start.