3
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ 1. Are the fuses default? Did you change them? 2. Can you include the output for avr-objdump -C -d test.elf ? 3. Are you on Windows/Linux/... 4. Also include the full output for your avrdude-command line. 5. Include a link to the datasheet of the controller. 6. If possible add a picture of your set up. \$\endgroup\$ – jippie Jun 3 '13 at 20:30
  • \$\begingroup\$ I use Linux. The output of avr-objdump: pastebin.com/htm68TPy \$\endgroup\$ – Ethan Leroy Jun 3 '13 at 20:36
  • \$\begingroup\$ Not sure why, but your program is not writing to the port registers at all, according to the disassembly. \$\endgroup\$ – jippie Jun 3 '13 at 20:53
  • 1
    \$\begingroup\$ Are you sure you want to flash the .elf file? \$\endgroup\$ – jippie Jun 3 '13 at 21:03
  • \$\begingroup\$ @jippie don’t the two st Z,r18 instructions write to the port registers through indirect addressing (which, admittedly, looks like an awkward way to do it) ? \$\endgroup\$ – microtherion Jun 3 '13 at 21:36
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Thanks! You were right. I didn't really want to flash the elf file. I wanted a hex file... \$\endgroup\$ – Ethan Leroy Jun 3 '13 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.