[Solved] Unable to program atmega168P/PA with custom Optiboot (at 4MHz)

Hey guys,

I'm using 3.3V and 4MHz for my project, and the idea is to be able to program the MCU onboard with an FTDI programmer.

My optiboot definition is the following:

atmega168p: TARGET = atmega168p
atmega168p: MCU_TARGET = atmega168p
	#115200 default
atmega168p: CFLAGS += '-DBAUD_RATE=19200'
	#16MHz default
atmega168p: AVR_FREQ = 4000000L
atmega168p: $(PROGRAM)_atmega168p.hex
atmega168p: $(PROGRAM)_atmega168p.lst

atmega168p_isp: atmega168p
atmega168p_isp: TARGET = atmega168p
# No brownout
atmega168p_isp: HFUSE = DF
# Ext Crystal 3- 8 Mhz
atmega168p_isp: LFUSE = FD
# 512 byte boot, 0x04?
atmega168p_isp: EFUSE = 0xFA
atmega168p_isp: isp

I've tested the EFUSE with both 0xFA and the complement =0x04, to no avail.

I'm uploading it to the chip with OptiLoader without problems after compiling, but the sketch just wont upload. Arduino IDE shows "sync error"

I've already tested the FTDI programmer and the wiring, changing the clock to 16 Mhz and programming the 328 of my Uno with the setup.

Thank you all in advance!

What's your boards.txt entry look like?

##############################################################

wsx168p.name = WSX w/ ATmega168P @ 4MHz

wsx168p.upload.protocol=arduino
wsx168p.upload.maximum_size=15872
wsx168p.upload.speed=19200

wsx168p.bootloader.low_fuses=0xed
wsx168p.bootloader.high_fuses=0xdf
wsx168p.bootloader.extended_fuses=0xfb
wsx168p.bootloader.file=optiboot/optiboot_atmega168p_4mhz.hex
wsx168p.bootloader.unlock_bits=0x3F
wsx168p.bootloader.lock_bits=0x0F
wsx168p.bootloader.tool=arduino:avrdude


wsx168p.build.mcu=atmega168p
wsx168p.build.f_cpu=4000000L
wsx168p.build.core=arduino
wsx168p.build.variant=standard
wsx168.build.board=AVR_ATMEGA168P


wsx168p.upload.tool=arduino:avrdude

I see my lfuses and efuses are off, forgot to change that, but is that actually relevant when programming (gonna fix it and try in any case)? Frequency and baudrate are ok.

Thanks!

EDIT: Fixing the fuses in boards.txt didn't help. My current doubt is regarding the lock bits (maybe thats preventing me from programming?

Solved! It was the damned lock bit! I was setting it to 0x0F and changing it to 0xCF solved it. Now I'm programming at 4 Mhz no problems

:slight_smile: