I would like to use an Atmega328p micro-controller with a 4 Mhz oscillator in order get some low power consumptions. I am using an Arduino board to flash the bootloader into the Atmega.
EDIT
In order to compile the optiboot bootloader I had to install the avr-libc package and clone the repo
sudo apt-get install avr-libc
git clone https://github.com/Optiboot/optiboot.git
and edited the Makefile in /optiboot/bootloaders/optiboot/Makefile
by adding a new entry called atmega328_4
HELPTEXT += "target atmega328 - ATmega328p 4Mhz\n"
atmega328_4: TARGET = atmega328
atmega328_4: MCU_TARGET = atmega328p
atmega328_4: CFLAGS += $(COMMON_OPTIONS)
atmega328_4: AVR_FREQ ?= 4000000L
ifndef BIGBOOT
atmega328_4: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
else
# bigboot version is 1k long; starts earlier
atmega328_4: LDSECTIONS = -Wl,--section-start=.text=0x7c00 -Wl,--section-start=.version=0x7ffe
endif
atmega328_4: $(PROGRAM)_atmega328_4.hex
atmega328_4: $(PROGRAM)_atmega328_4.lst
atmega328_4_isp: atmega328
atmega328_4_isp: TARGET = atmega328
atmega328_4_isp: MCU_TARGET = atmega328p
ifndef BIGBOOT
# 512 byte boot, SPIEN
atmega328_4_isp: HFUSE ?= D9
else
# 1k byte boot, SPIEN
atmega328_4_isp: HFUSE ?= D9
endif
# Low power xtal 46MHz) 16KCK/14CK+65ms
atmega328_4_isp: LFUSE ?= 7D
# 2.7V brownout
atmega328_4_isp: EFUSE ?= FE
atmega328_4_isp: isp
I saved the file, run the make command and got the following error:
userk@norepinephrine:~/development/git/optiboot/optiboot/bootloaders/optiboot$ make atmega328_4
avr-gcc (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
BAUD RATE CHECK: Desired: 115200, Real: 125000, UBRRL = 3, Difference=8.5%
avr-gcc -g -Wall -Os -fno-split-wide-types -mrelax -mmcu=atmega328p -DF_CPU=4000000L -DBAUD_RATE=115200 -DLED_START_FLASHES=3 -c -o optiboot.o optiboot.c
optiboot.c:348:6: error: #error BAUD_RATE off by greater than 5%
#error BAUD_RATE off by greater than 5%
^
optiboot.c:359:2: error: #error Unachievable baud rate (too fast) BAUD_RATE
#error Unachievable baud rate (too fast) BAUD_RATE
^
<builtin>: recipe for target 'optiboot.o' failed
make: *** [optiboot.o] Error 1
So I changed the -DBAUD_RATE parameter to 19200 and rerun the make command
BAUD_RATE_CMD = -DBAUD_RATE=19200
Then 2 new files were created: optiboot_atmega328_4.elf and optiboot_atmega328_4.hex
Then I copied these files into the arduino configuration folder located
at: /home/userk/.arduino15/packages/arduino/hardware/avr/1.6.21/bootloaders/optiboot
TIDE
I am using a custom board configuration file board.txt
##############################################################
nz.name=Arduino Noize
nz.vid.0=0x2341
nz.pid.0=0x0043
nz.vid.1=0x2341
nz.pid.1=0x0001
nz.vid.2=0x2A03
nz.pid.2=0x0043
nz.vid.3=0x2341
nz.pid.3=0x0243
nz.upload.tool=avrdude
nz.upload.protocol=arduino
nz.upload.maximum_size=32256
nz.upload.maximum_data_size=2048
nz.upload.speed=19200
nz.bootloader.tool=avrdude
nz.bootloader.low_fuses=0x7D
nz.bootloader.high_fuses=0xD9
nz.bootloader.extended_fuses=0xFE
nz.bootloader.unlock_bits=0x3F
nz.bootloader.lock_bits=0x0F
nz.bootloader.file=optiboot/optiboot_atmega328_4.hex
nz.build.mcu=atmega328p
nz.build.f_cpu=4000000L
nz.build.board=AVR_UNO
nz.build.core=arduino
nz.build.variant=standard
Flashing the Bootloader I have followed these steps:
Uploaded the ArduinoISP sketch onto the Arduino UNO board.
Wired up the Arduino board and microcontroller as shown in the diagram below
Select "Arduino Noize" from the Tools > Board menu.
Select "Arduino as ISP" from Tools > Programmer Run Tools > Burn Bootloader
At this point I got a success message from IDE. So the bootloader has been correctly flashed into the Atmega328p
The Problem
When I try to upload a sample sketch (blink) using the wiring below I get a timeout from the IDE.
I have double checked the connections but the sketch doesn't upload. Do you have any advice?