Bootloading error

Hello,

I have been struggling with bootloading problem for weeks now and have no other choice then to ask for help from community.

I am using Arduino compatible boards(compatible to Arduino Duemillanove, Atmega328 + FT232R) and trying to bootload using two of them, one as a programmer, other as target board: http://arduino.cc/en/Tutorial/ArduinoISP I had a batch of 200pcs, which 150 were bootloaderd fine, but with 50 I have same problem. If I am bootloading with: a) Arduino software(which with I bootloaded those 150 pieces), I got "invalid device signature" error(note: I do get the other part; " Expected signature for ATMEGA328P is xx xx xx"). Tried changing Atmega signature from 14 to 0F with no results. Then I thought, I could use -F in avrdude, so I downloaded Crossover(I'm on Mac), installed it and tried to bootload with Optiboot bootloader using this command line: (corresponding to my serial port and .hex file location)

avrdude -P /dev/tty.usbserial-A9WNJD1D -b 19200 -c avrisp -p m328p -v -e -U flash:w:/optiboot_atmega328.hex -U lock:w:0x0F:m -F

Everything seems fine until finish, where I got verification error:

avrdude: Version 5.11.1, compiled on Feb 12 2013 at 01:24:54
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/local/CrossPack-AVR-20130212/etc/avrdude.conf"
         User configuration file is "/Users/David/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/tty.usbserial-A9WNJD1D
         Using Programmer              : avrisp
         Overriding Baud Rate          : 19200
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : STK500
         Description     : Atmel AVR ISP
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.06s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: erasing chip
avrdude: reading input file "/optiboot_atmega328.hex"
avrdude: input file /optiboot_atmega328.hex auto detected as Intel Hex
avrdude: writing flash (32768 bytes):

Writing | ################################################## | 100% 0.64s

avrdude: 32768 bytes of flash written
avrdude: verifying flash memory against /optiboot_atmega328.hex:
avrdude: load data flash data from input file /optiboot_atmega328.hex:
avrdude: input file /optiboot_atmega328.hex auto detected as Intel Hex
avrdude: input file /optiboot_atmega328.hex contains 32768 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 24.72s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x00
avrdude: verification error; content mismatch

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

I am unable to think of any other solutions to this problem. Maybe some of you can notice my mistake somewhere?

Thanks on your time, David

In-Circuit Serial Programming (ICSP, or ISP) requires the target chip to have a working system clock. For factory-fresh chips the system clock is set to the internal 8 MHz RC clock divided by 8 (so 1 MHz). If the chips have had an Arduino bootloader installed they will likely be set for an external crystal clock. If they are set for an external crystal and you don't provide the crystal those chips can't be programmed by ISP.

When you try to program the chip is it connected to a crystal?

Other possibilities: You got some ATmega328 chips instead of ATmega328P. The chip fuses have been set to dis-allow ISP. The chip fuses have been set to disable the Reset pin (to allow it to be used as a data pin).

Take a look at this thread: http://forum.arduino.cc//index.php?topic=129459.0