First a bit of background:
I have an ATmega324a MCU (should be the same as the p and pa variant) with a 8 MHz crystal (should use 18 pF caps, I've put 15 pF).
It runs on 5V (supplied by a working Arduino Duemilanove). I have a test LED on PA7, USART0 on PD0/PD1 connected to MAX232 to a real serial port /dev/ttyS0.
I can program the ATmega324a without problems via ISP (using Arduino on /dev/ttyUSB0 as the avrisp) as well as I've tested the serial communication in both direction by means of a short sketch, which replies after 1 second what I've written to ATmega324a. If I make a sketch for blinking the LED, it blinks in correct intervals. My fuses are lfuse: 0xFF, hfuse: 0xD8, efuse: 0x04. To the serial port I've connected only three wires: Rx, Tx, GND.
My problem:
Can't get a bootloader to work, so that I could upload code via serial port instead of ISP.
What I've tried:
I've added to optiboot files in /usr/share/arduino/hardware/arduino/bootloaders/optiboot/ the following things:
To optiboot.c:
#if defined(__AVR_ATmega324A__)
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */
#define LED_DDR DDRA
#define LED_PORT PORTA
#define LED_PIN PINA
#define LED PINA7
/* Ports for soft UART */
#ifdef SOFT_UART
#define UART_PORT PORTD
#define UART_PIN PIND
#define UART_DDR DDRD
#define UART_TX_BIT 1
#define UART_RX_BIT 0
#endif
#endif
To Makefile:
atmega324: TARGET = atmega324
atmega324: MCU_TARGET = atmega324a
atmega324: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega324: AVR_FREQ = 8000000L
atmega324: LDSECTION = --section-start=.text=0x7e00
atmega324: $(PROGRAM)_atmega324.hex
atmega324: $(PROGRAM)_atmega324.lst
atmega324_isp: atmega324
atmega324_isp: TARGET = atmega324a
atmega324_isp: HFUSE = DE # 2.7V brownout
atmega324_isp: LFUSE = FF # Internal 8MHz osc (8MHz) Slow rising power
atmega324_isp: EFUSE = FC # 512 byte boot
atmega324_isp: isp
I've also added to boards.txt in /usr/share/arduino/hardware/arduino:
atmega324.name=Atmega324a
atmega324.upload.protocol=arduino
atmega324.upload.maximum_size=32256
atmega324.upload.speed=115200
atmega324.bootloader.low_fuses=0xff
atmega324.bootloader.high_fuses=0xd8
atmega324.bootloader.extended_fuses=0xfc
atmega324.bootloader.path=optiboot
atmega324.bootloader.file=optiboot_atmega324.hex
atmega324.bootloader.unlock_bits=0x3F
atmega324.bootloader.lock_bits=0x0F
atmega324.build.mcu=atmega324p
atmega324.build.f_cpu=8000000L
atmega324.build.core=arduino
And modified the Arduino IDE's avrdude.conf:
signature = 0x1e 0x95 0x08; (at m324p)
to
signature = 0x1e 0x95 0x15;
I then compiled the bootloader by means of: sudo make -t Makefile atmega324
It created the hex., which I've uploaded successfully with:
avrdude -P /dev/ttyUSB0 -b 19200 -c avrisp -p m328p -F -v -U flash:w:optiboot_atmega324.hex -U lock:w:0x0F:m
I use -F because I haven't modified the /etc/avrdude.conf.
The LED flashes 3 times.
If I try now avrdude -P /dev/ttyS0 -b 115200 -c arduino -p m328p -F -v -v -U flash:w:optiboot_atmega324.hex
I get:
avrdude: Version 5.10, compiled on Jun 29 2010 at 03:44:14
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg WunschSystem wide configuration file is "/etc/avrdude.conf"
User configuration file is "/root/.avrduderc"
User configuration file does not exist or is not a regular file, skippingUsing Port : /dev/ttyS0
Using Programmer : arduino
Overriding Baud Rate : 115200
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not respondingavrdude done. Thank you.
I've also tried burning the bootloader from Arduino IDE. Selecting the board "atmega324a", serial port /dev/ttyUSB0 and Burn Bootloader w/Arduino as ISP.
It works without problems and at the end the LED of ATmega324a flashes. If I now select the /dev/ttyS0 and try to upload the Blink sketch I get the "programmer is not responding" error.
Please show me where have I failed.