Optiboot on AtMega328 @ 8Mhz

I built my own Arduino. Loaded firmware onto the 8U2, computer recognizes it as an Arduino Uno. Loaded optiboot_atmega328.hex onto the AtMega328. The AtMega328 is running @ 8Mhz on the internal clock.

Double checked that my serial connections are correct. I select "Arduino Uno" as the board and the proper COM port, and get this error when trying to upload a sketch: avrdude: stk500_getsync(): not in sync: resp=0x00

I have also added the following to boards.txt and did not have success using this board either:

atmega328_8.name=ATmega328 Optiboot (8 MHz internal clock)

atmega328_8.upload.protocol=arduino
atmega328_8.upload.maximum_size=32256
atmega328_8.upload.speed=57600

atmega328_8.bootloader.low_fuses=0xe2
atmega328_8.bootloader.high_fuses=0xde
atmega328_8.bootloader.extended_fuses=0x05
atmega328_8.bootloader.path=arduino:optiboot
atmega328_8.bootloader.file=optiboot_atmega328.hex
atmega328_8.bootloader.unlock_bits=0x3F
atmega328_8.bootloader.lock_bits=0x0F

atmega328_8.build.mcu=atmega328p
atmega328_8.build.f_cpu=8000000L
atmega328_8.build.core=arduino:arduino
atmega328_8.build.variant=arduino:standard

Do I need to run a specific version of optiboot for running at 8Mhz, or should I look into another problem?

As a side note, I thought AtMega8U2's were supposed to come from the factory with the internal oscillator fuse set. But the one I got was set to an external crystal and required one to start up. Is that normal?

monkey123: Do I need to run a specific version of optiboot for running at 8Mhz, or should I look into another problem?

Yes. The baud rate is based on the system clock so you either have to compile a special 8 MHz bootloader or you have to use a baud rate half of what the 16 MHz bootloader expects. Try:

atmega328_8.upload.speed=28800

Same error at 28800. I should also mention I did correctly set the boot size and boot reset fuses as well.

Perhaps I'll try it at the regular 16Mhz and add an external crystal?

Added an external crystal, set SUT_CKSEL fuse to EXTXOSC_8MHZ_XX_16KCK_14CK_65MS

Chip is still readable and running fine, and presumably running at 16Mhz. Same error when trying to upload a sketch: avrdude: stk500_getsync(): not in sync: resp=0x00

BODLEVEL fuse disabled SPIEN fuse is set to enabled BOOTSZ fuse is set to 512W_3E00 BOOTRST fuse is set to enabled SUT_CKSEL fuse set to EXTXOSC_8MHZ_XX_16KCK_14CK_65MS

All other fuses disabled.

monkey123:
Do I need to run a specific version of optiboot for running at 8Mhz, or should I look into another problem?

Yes. Here is one I compiled. Note upload speed of 57600. I have not tried it using an 8U2, just bare AVRs and FTDI. So YMMV, but let us know what happens!

http://forum.arduino.cc/index.php/topic,101064.msg760450.html#msg760450

Do the chip fuses and lock bits have to exactly match those in the boards.txt file?

monkey123:
Do the chip fuses and lock bits have to exactly match those in the boards.txt file?

After doing “Burn Bootloader” (an ICSP programmer is required) the fuses and lock bit will match, that is part of the process. But I see you want to use the internal RC oscillator, so change the fuse bytes in the boards.txt file appropriately (the boards.txt entry in the thread I linked above assumes an external crystal).

Be aware that the internal oscillator is only guaranteed by the factory to be calibrated to ±10%. Therefore async comm (and therefore the bootloader) cannot be guaranteed to work with the internal oscillator. I’ve actually had pretty good luck with that myself, but only at 9600 baud, and not with a bootloader, programming via ICSP and just using async comm for debugging. Given that, you might try recompiling Optiboot for 9600 baud, but there’s still no guarantee.

I just use the Lilypad bootloader which is already compiled for 8 Mhz. Fuses - low:FD high:DA extended:FD or as you wish from http://www.engbedded.com/fusecalc.

[quote author=Jack Christensen link=topic=191592.msg1416353#msg1416353 date=1380936781]

monkey123: Do the chip fuses and lock bits have to exactly match those in the boards.txt file?

After doing "Burn Bootloader" (an ICSP programmer is required) the fuses and lock bit will match, that is part of the process. But I see you want to use the internal RC oscillator, so change the fuse bytes in the boards.txt file appropriately (the boards.txt entry in the thread I linked above assumes an external crystal).

Be aware that the internal oscillator is only guaranteed by the factory to be calibrated to ±10%. Therefore async comm (and therefore the bootloader) cannot be guaranteed to work with the internal oscillator. I've actually had pretty good luck with that myself, but only at 9600 baud, and not with a bootloader, programming via ICSP and just using async comm for debugging. Given that, you might try recompiling Optiboot for 9600 baud, but there's still no guarantee. [/quote]

I've uploaded optiboot using ICSP headers via Atmel Studio, and have therefore set the fuses manually in that application.

monkey123: I've uploaded optiboot using ICSP headers via Atmel Studio, and have therefore set the fuses manually in that application.

That should be fine but the issue of the accuracy of the internal RC oscillator for serial comm remains.