ATMega32 USBasp not programming

atmegaavravrdudemicrocontrollerusbasp

I use no Arduino just trying to program a simple ATMega32 using USBASP. Getting this message:

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

avrdude done.  Thank you.

Explanation:

I use an AVR development board with 8.00:

AVR developement board

To make the AVR model label more clear, I have made this photo as well (photo)

To program the microcontroller, I use a USBASP. The crystal of the programmer is 12.0 MHz (though might not be relevant).

USBASP programmer

I installed Avrdude on ubuntu and wrote the following program:

// main.c

#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>

int main(void) {

 DDRD = 255;
 PORTD=255;

 DDRC = 255;

 while(1){

 PORTC=255;
 _delay_ms(200);

 PORTC=0;
 _delay_ms(200);
 }

 return 0;
}

Then compiled and made hex file:

avr-gcc -w -Os -DF_CPU=8000000UL -mmcu=atmega32 -c -o main.o main.c
avr-gcc -w -mmcu=atmega32 main.o -o main
avr-objcopy -O ihex -R .eeprom main main.hex

Till now main.hex file is created successfully.

Then, trying to load it into microcontroller:

sudo avrdude -p m32 -c usbasp -B 8 -v -e -u -U flash:w:main.hex

And the output is disappointing. I mean the last part:

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

avrdude done.  Thank you.

The full message is:

avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/me/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : usb
         Using Programmer              : usbasp
         Setting bit clk period        : 100.0
         AVR Part                      : ATmega32
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
           flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
           calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

         Programmer Type : usbasp
         Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: set SCK frequency to 8000 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502
avrdude: erasing chip
avrdude: set SCK frequency to 8000 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
avrdude: writing flash (162 bytes):

Writing | ################################################## | 100% 0.15s

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

Reading | ################################################## | 100% 0.10s

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

avrdude done.  Thank you.

Here is the way I have connected the microcontroller while downloading the hex file:

Downloading hex file

When I check the communication, it seems to be alright:

sudo avrdude -p m32 -c usbasp -t

The response:

avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502
avrdude> 

So what is wrong? What to do?


It seems nothing is programmed. I checked it with a 5VDC adaptor (photo) and a breadboard with LED and capacitor. Connecting LED to VCC turns it on (photo) which shows LED is working. Connecting to any pin of port D does not turn on the LED (photo) connecting to some pins of port C turn on the LED (photo) and some don't (photo). But there is no blink. Note that I am using a virgin ATMega32 chip.


Update

Inspired from this website (btw, I dont know German!) and a few others, finally I used the following command:

sudo avrdude -p m32 -c usbasp -v -b 19200 -B5 -e -U flash:w:main.hex -U lfuse:w:0xe4:m -U hfuse:w:0x99:m

Response:

avrdude: Version 6.0.1, compiled on Oct 21 2013 at 15:55:32
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/home/me/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping
     Using Port                    : usb
     Using Programmer              : usbasp
     Overriding Baud Rate          : 19200
     Setting bit clk period        : 5.0
     AVR Part                      : ATmega32
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PA0
     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         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
       flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
       lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
       lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
       calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

     Programmer Type : usbasp
     Description     : USBasp, http://www.fischl.de/usbasp/

avrdude: set SCK frequency to 187500 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9502
avrdude: safemode: lfuse reads as E4
avrdude: safemode: hfuse reads as 99
avrdude: erasing chip
avrdude: set SCK frequency to 187500 Hz
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
avrdude: writing flash (162 bytes):

Writing | ################################################## | 100% 0.11s

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

Reading | ################################################## | 100% 0.07s

avrdude: verifying ...
avrdude: 162 bytes of flash verified
avrdude: reading input file "0xe4"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe4:
avrdude: load data lfuse data from input file 0xe4:
avrdude: input file 0xe4 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0x99"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0x99:
avrdude: load data hfuse data from input file 0x99:
avrdude: input file 0x99 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified

avrdude: safemode: lfuse reads as E4
avrdude: safemode: hfuse reads as 99
avrdude: safemode: Fuses OK (H:FF, E:99, L:E4)

avrdude done.  Thank you.

Seems it works!!!

Now, all pins on portD turn on the LED bright and pin C0, C1, C6 and C7 blink bright while C2, C3, C5 give dim but constant light to LED and C4 does not turn on the LED at all.

Though, I am very happy of writing something into the chip, could someone explain what has happened?

Best Answer

It seems the problem was in baud rate. "-b 19200" was the solution.

A promt was in line: "avrdude: warning: cannot set sck period. please check for usbasp firmware update."