Electronic – LED remains off on ATmega16

atmegaavravr-gccavrdude

I wrote this simple program:

#include <avr/io.h>

int main(void) {
  DDRA = 0xff;
  PORTA = 0xff;
  while(1) {
  }
}

When I program it to my brand new ATmega16A-PU, avrdude tells me that everything's fine. But when I connect an LED to port A, it never gets enabled.

For compiling the program and flashing it onto the ATmega, I use the following commands:

avr-gcc -mmcu=atmega16 -c -o test.o test.c
avr-gcc -mmcu=atmega16 -o test.elf test.o
avrdude -p m16 -c avrispv2 -P usb -U flash:w:test.elf

The following pins of the microcontroller are connected:

40 PA0 ---------> 220 Ω --> green LED --> GND
06 PB5 (MOSI) --> MOSI of the programmer
07 PB6 (MISO) --> MISO of the programmer
08 PB7 (SCK) ---> SCK of the programmer
09 RESET -------> RESET of the programmer
10 VCC ---------> VCC of the programmer
11 GND ---------> GND of the programmer

When I connect the left end of the 220 Ω resistor directly to VCC, the LED glows, so the LED is ok. The microcontroller is brand new and I already tried another one (also brand new), so I think they are ok too.

EDIT: the fuses are set to 0b10011001 (high) and 0b11100001 (low).

Any idea, why the microcontroller does not set port PA0 to VCC?

Best Answer

Too much details for a comment, so I chose to write it as answer.

Try these commands:

cflags="-g -DF_CPU=1000000 -Wall -Os -Werror -Wextra"
avrType=m16

avr-gcc ${cflags} -mmcu=${avrType} -Wa,-ahlmns=test.lst -c -o test.o test.cpp
avr-gcc ${cflags} -mmcu=${avrType} -o test.elf test.o
avr-objcopy -j .text -j .data -O ihex test.elf test.hex
avrdude -p ${avrType} -c avrispv2 -P usb -v -U flash:w:test.hex

Check http://git.linformatronics.nl/gitweb/?p=makefile;a=summary for a generic Makefile. It'll need some tweaking as I am using a different programmer and controller, but it should be pretty straightforward.