Electronic – Unable to program ATmega128 – 16AU using USBasp

atmegaavrispprogrammer

I am trying to program an ATmega128 microcontroller (bought from Robokits). I have connected the 10 pin ISP header from the USBasp programmer to the 6 pins (MOSI, MISO, SCK, RESET, VCC, GROUND) of the MCU.

But whenever I try to program the MCU the result is:

C:\Documents and Settings\intern>avrdude -p m128 -c usbasp
avrdude: warning: cannot set sck period. please check for usbasp firmware update
avrdude: error: programm enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
     Double check connections and try again, or use -F to override
     this check.
avrdude done.  Thank you.

Also I tried connecting an external 8MHz crystal to the MCU as indicated in this post, but it didn't work.

ATmega128 - Image

enter image description here

Best Answer

Pin 1 (nPEN) is supposed to be held low during power-on, so the SPI programming is possible.

nPEN has internal pull-up, so grounding this pin during power-on is a must, otherwise you cannot program it with the USBasp.

"PEN is a programming enable pin for the SPI Serial Programming mode, and is internally pulled high . By holding this pin low during a Power-on Reset, the device will enter the SPI Serial Programming mode. PEN has no function during normal operation. "

So you will need to remove the grounding on Pin 1 for normal start up behavior.

  • You will also need to use the pins PE0 as MOSI, PE1 as MISO, and SCK as SCK. This is all described in the SPI Serial Programming section on page 300 in the datasheet for ATmega128.