atmega324p bootloader can't write flash [SOLVED]

Hello, 1/ I have device atmega324p, I downloaded the bootloader from site: 2/ I modified a little bit the "Makefile" and "ATmegaBOOT.c" for chip atmega324p, speed 19200, cpu_speed 16MHz 3/ I burned it by avrdragon 4/ I joined RS232-TTL (max232) cabel to PC and to the chip 5/ I made a successful test:

$ avrdude -c avrisp -p m324p -P com1 -b 19200 -F -U flash:r:readout:i

6/ but writing doesn't work

$ avrdude -c avrisp -p m324p -P com1 -b 19200 -F -U flash:w:main_blinking.hex:i

What is wrong? Please any advice how to upload atmega324p chip? Or does someone provide Arduino IDE files for chip atmega324p?

You have specified to avrdude to program the chip using ISP (note the avrisp), and yet you are trying to use a bootloader. The two are very different.

Off the top of my head I can't remeber what ATmegaBOOT uses in relation to avrdude. I think that optiboot is 'arduino' (instead of avrisp), or is it 'stk500v1'. Would have to check.

EDIT: Try this: avrdude -c arduino -p m324p -P com1 -b 19200 -D -U flash:w:main_blinking.hex:i

Thank you. Today I have found the bug. I forgot change line 119 in ATmegaBOOT.c for chip m324p. Now it works both reading & writing. Bootloader code is here:

$ avrdude -c avrisp -p m324p -P com5 -b 19200 -F -D -U flash:r:readout.hex:i
$ echo 'this one reads the chip'

$ avrdude -c avrisp -p m324p -P com5 -b 19200 -F -D -U flash:w:main.hex:i
$ echo 'this one writes the chip'

$ echo '-c arduino instead of -c avrisp works too'