8Mhz Arduino with garbage serial output

I am trying to create an 8Mhz standalone Arduino using its internal oscillator.

Using Nick Gammon’s GitHub - nickgammon/arduino_sketches: Publicly-released sketches for the Arduino microprocessor I eventually managed to get a bootloader on a chip and change the lfuse settings by choosing the Lilypad option as suggested using the Atmega_Board_Programmer.ino

After some fiddling I also managed to get the IDE (v1.8.2) to appear to let me upload a simple sketch with a serial.println in the loop. Worked fine when it was a 16MHz chip with an external oscillator.
I needed to select the target as Nano/ATMega328, as suggested in https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard.

The IDE serial monitor opens but the serial output is garbage. I tried setting the baud rate to all settings and I also changed the baud rate in the program and tried reopening the serial monitor. No joy, Just the sort of garbage you tend to see when you open it with the wrong baud setting.

An ideas please? Anyone need more information in order to help me?

Cheers Alan

The internal oscillator probably needs calibration. Many people consider the the internal oscillator to be unsuitable for reliable serial communication. Try Google for calibration procedures. The data sheet also gives a little information.

I have several Atmega 328s and Attiny1634s working with the internal 8MHz oscillator and have no trouble with serial comms at 500,000 baud. I have never had to calibrate anything.

I used this tutorial for setting up the Atmega 328s

...R

My gut reaction is that 'it should have worked'... and tuning the oscillator shouldn't be necessary. Not saying that isn't the answer but...

I wonder if I've messed up with the settings - but wouldn't that have stopped the uploading???

Anyone who has done this care to share the details of the path they followed?

@robin2 - I looked over that page. I'll revisit.

Cheers Alan

You could hook up a cheap logic-analyzer to the tx pin and figure out what the bitrate really is.

IIRC there are some combinations of bootloader, fuses, oszillator and frequency that mess things up.

If the software assumes a wrong basic-frequency it will not program the UARTs correctly.

I forgot to mention that Nick Gammon has a very useful diagnostic program.

…R

Tried the detector from Nick Gammon’s github and everything looks okay but there is a lot of information to understand.

When I get back to the workbench I’ll fiddle with boards.txt and add the barebones arduino on that pagehttps://www.arduino.cc/en/Tutorial/ArduinoToBreadboard .

I’ll also check out the .hex file in the download to see if its the same as the one on my 1.8.2 download… not sure what I’ll do if they aren’t the same though.

I’ll also try and hook up the logic analyser and see what “hello” on a good 16Mhz Arduino looks like compared to my 8Mhx word slurring drunken one.

Cheers Alan

I don't think you have told us what baud rate you are using when you have the problem? Some work better than others. There is a table in the Atmega328 datasheet.

...R

I tried loads different baud rates... however I now have some data from the logic analyser.

Good 16Mhz Arduino at 9600 baud. Logic analyser reads the text and reports 10000 bits/second and IDE serial monitor reads it okay as does Putty and my serial monitor.

Drunken 8Mhz Arduino also programmed at 9600 baud. The logic analyser can also read the serial output as 'hello' but reports 5000 bits/second. My attempt to open Putty, IDE and my own serial monitor (ESM) at 4800 produces desired text. (Can't believe I didn't try a simple factor of the setting in my test... doh).

So I set the baud at 500000 and it works if the serial monitors are at 250000. So the problem moves around to why it does this and is this solvable... Really would be nice to set a baud rate and open the port at the same speed (hey, I'm just old fashioned).

Cheers
Alan

Check your F_CPU is set to match your oscillator fuses & settings.

lastchancename:
Check your F_CPU is set to match your oscillator fuses & settings.

Will do… er, how do I do that?

Cheers
Alan

Your 8 MHz Arduino believes it runs on 16 MHz.

Try 19200 baud for the drunken, and receive with 9600 baud.

That’s a great idea for a quick fix/test.

I suspect the hardware is correct but the compiler is assuming a 16MHz chip - probably because of selecting the wrong board for uploading. I treat my 8MHz Atmega 328s as a Lilypad

...R

Just tried LilyPad and serial monitors receive at the same rate as the Arduino is coded to send :slight_smile:

Works, but not very elegant. Will pursue when I have more time to create something that sounds/looks right.

Cheers
Alan

So I couldn't sleep...

Added the BB boards txt file to the main one in C:\arduino-1.8.2\hardware\arduino\avr and got a more useful looking option in the IDE called ATmega328 on a breadboard (8 MHz internal clock).

Does generate a warning on compile/upload

Warning: Board arduino:avr:atmega328bb doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA328BB

but otherwise seems to make the Arduino do my simple test sketch properly. More tests tomorrow :slight_smile:

Cheers
Alan

Not quite there yet :frowning:

I appear to have a raw ATMEGA328 loaded for 8Mhz internal clock. I have uploaded a simple sketch with serial output and it runs without the external oscillator.

However it will not run below 3.7v. According to the ATMEL documentation this looks like the lower operational limit for when the chip is running at 16MHz.The chip should run at a lot lower voltage than this.

These are the fuse settings on my chip as per Gammon's Programmer for the Lilypad.

Low fuse is 0xE2 (b11100010)which means CKSEL3..0 is b0010 which I read from the ATMEL docs as meaning the clock speed is 8MHz internal (Calibrated Internal RC Oscillator)

High fuse is 0xDA
Ext fuse is 0xFD
Lock Byte is 0xEF
Clock calib is 0x8C

What am I overlooking? Is my uploaded sketch conflicting with what has been set? I note the fuse settings in boards.txt are different.

Here is the info from boards.txt for the target device

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

atmega328bb.upload.protocol=arduino
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.file=atmega/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.board=AVR_ATMEGA328BB
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard


atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdude

Cheers
Alan

I don't have any easy way to check the fuse settings on my 8MHz Atmega 328s - I will try to find time later. My guess is that the boards.txt should match the actual fuses. My 8MHz 328s run very happily on a pair of AA alkaline cells.

...R

This is the output from running Nick Gammon's program for one of my 8MHz Atmega 328s

Attempting to enter ICSP programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F 
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xE2 
HFuse = 0xDA 
EFuse = 0xFD 
Lock byte = 0xCF 
Clock calibration = 0x9F 
Bootloader in use: Yes
EEPROM preserved through erase: No
Watchdog timer always on: No
Bootloader is 2048 bytes starting at 7800

And I think this is the relevant piece from boards.txt

lilypad.name=LilyPad Arduino

lilypad.upload.tool=avrdude
lilypad.upload.protocol=arduino

lilypad.bootloader.tool=avrdude
lilypad.bootloader.unlock_bits=0x3F
lilypad.bootloader.lock_bits=0x0F

lilypad.build.f_cpu=8000000L
lilypad.build.board=AVR_LILYPAD
lilypad.build.core=arduino
lilypad.build.variant=standard

## LilyPad Arduino w/ ATmega328
## ----------------------------
lilypad.menu.cpu.atmega328=ATmega328

lilypad.menu.cpu.atmega328.upload.maximum_size=30720
lilypad.menu.cpu.atmega328.upload.maximum_data_size=2048
lilypad.menu.cpu.atmega328.upload.speed=57600

lilypad.menu.cpu.atmega328.bootloader.low_fuses=0xFF
lilypad.menu.cpu.atmega328.bootloader.high_fuses=0xDA
lilypad.menu.cpu.atmega328.bootloader.extended_fuses=0x05
lilypad.menu.cpu.atmega328.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex

lilypad.menu.cpu.atmega328.build.mcu=atmega328p

And it looks like the fuses don't match !

By the way this is with Arduino IDE 1.6.3

...R

I've tried 3 chips through the Lilypad (Nick Gammon's programmer) to ATmega328 on a breadboard with 8 MHz internal clock,

None of them run properly below 3.7v unless I take out the serial.print and just have an LED blinking when it runs at just over 3.2v. Can that be true? as the programmer based on cp2102 is self powering from the USB on the PC.

My BOD settings in the extended fuses are set to 2.7v

My apologies to anyone with 50 miles of my house who can hear me groaning.