Trying to flash an ATMega168 on a breadboard with an Uno R3 as ISP

Hi all,

I’m a bit stuck I’m afraid. I’ve been reading a ton of tutorials, read the 168’s datasheet more times than I can remember but all to no avail.

I have a project that I’m trying to flash an ATMega168-20PU for. I’ve put it on a breadboard, put the “Arduino as ISP” sketch on my Uno R3 and made the following connections:

I’ve managed to flash the blink sketch twice, once using pin 13 for the LED, once with pin 12. Why? I couldn’t get the LED to blink. I was using Pin28 (digital 13) and Pin27 (digital 12) on the DIP package. Didn’t work.

Then I tried to flash the sketch onto the 168 that I was eventually going to be flashing anyway and ever since I’ve had the same error with the Blink sketch as well:

Sketch uses 1,030 bytes (7%) of program storage space. Maximum is 14,336 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 1,015 bytes for local variables. Maximum is 1,024 bytes.
/Applications/Arduino 1.6.4.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino 1.6.4.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -v -patmega168 -carduino -P/dev/cu.usbmodem3a11 -b19200 -D -Uflash:w:/var/folders/7w/0g6glz_s1595bs530bsr6_0r0000gn/T/build4418102194544715516.tmp/Blink.cpp.hex:i 

avrdude: Version 6.0.1, compiled on Apr 14 2015 at 16:30:25
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/Applications/Arduino 1.6.4.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Users/sebastiaanswinkels/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodem3a11
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega168
         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        512    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     16384  128    128  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 : Arduino
         Description     : Arduino
         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.01s

avrdude: Device signature = 0x1e9406
avrdude: reading input file "/var/folders/7w/0g6glz_s1595bs530bsr6_0r0000gn/T/build4418102194544715516.tmp/Blink.cpp.hex"
avrdude: writing flash (1030 bytes):

Writing | ################################################## | 100% 1.42s

avrdude: 1030 bytes of flash written
avrdude: verifying flash memory against /var/folders/7w/0g6glz_s1595bs530bsr6_0r0000gn/T/build4418102194544715516.tmp/Blink.cpp.hex:
avrdude: load data flash data from input file /var/folders/7w/0g6glz_s1595bs530bsr6_0r0000gn/T/build4418102194544715516.tmp/Blink.cpp.hex:
avrdude: input file /var/folders/7w/0g6glz_s1595bs530bsr6_0r0000gn/T/build4418102194544715516.tmp/Blink.cpp.hex contains 1030 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.87s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
         0x14 != 0x5c
avrdude: verification error; content mismatch

avrdude done.  Thank you.

I have no bootloader flashed onto the 168 since I will be flashing it over the ICSP header (or at least the corresponding pins). As board I’ve selected the Lilypad Arduino w/ ATMega168 and the serial port is set correctly as well.

Any help would be greatly appreciated =)

Fixed it. I installed AVRFuses (for mac) and CrossPack from ObDev. Then, using the circuit in the sketch above, I had AVRFuses clear the 168. Then I used the Arduino IDE (1.6.4) to burn the Lilypad Arduino w/ 168 boatloader on the chip. That worked

Then I had the IDE create a hex file by verifying a sketch and then looking up the hex file in Arduino's temporary files. I then took that file and used AVRFuses to write it to the 168, which worked. It even verified okay.

Then I realized that digital pin 13 isn't located on PIN28 of the DIP package, even though it's labeled PCINT13. It's actually on PIN19, which I honestly should've realized a lot sooner.