Thank you for your instant response.
I am sorry if I was unclear
about that: I do *not* want the ISR to be called. The LED should turn on
because I enable it in main(), however, the uC goes straight to the
ISR!
For example, if I set the LED to high in the ISR and set it
to low in main(), it will be set to high and the LED will turn on when I
flash it. Even though I used cli()!
This behavior appears to
depend on -Os, so I guess I am either using the tools incorrectly, or
there is a bug in the optimization code.
8. Mai 2016 11:22 von
address@hidden:
First off, you are disabling global interrupts (cli ()). You need to enable them (sei ()). I presume you are toggling the LED in ISR, if so the LED will not toggle as interrupts are disabled.
Regards,
Parthasaradhi
Hyderabad
Hello,
I have been working on a project for some time and at some point, everything just stopped working. It appears that as soon as I include an ISR in my C code, the main function won't even be called anymore. I reduced my code to this:
#include <avr/io.h>
#include <avr/interrupt.h>
int main (void) {
cli();
DDRB = 0xff;
while(1) PORTB |= (1 << PB5);
return 0;
}
ISR(TIMER0_OVF_vect) {}
But the LED just won't turn on. The strange thing is: If I remove the ISR at the bottom without changing anything else, even keeping the include, everything works. If I remove the -Os option from gcc but keep the ISR, everything works.
I use these commands to compile, link and flash it:
F_CPU=16000000L
avr-gcc -Wall -DF_CPU=$F_CPU -c -mmcu=atmega168 -Os main.c -o main.o
avr-ld -mavr5 -o led-test.elf main.o
avr-objcopy -O ihex led-test.elf led-test.hex
sudo avrdude -c avrisp2 -p atmega168 -P usb -b 57600 -U flash:w:led-test.hex
I am quite new to the avr tools so I might just have made a silly mistake, so I would appreciate any tips!
Thank you!
LSB:
Distributor ID: Ubuntu
Description: Ubuntu 16.04 LTS
Release: 16.04
Codename: xenial
Output of avr-gcc -v:
Using built-in specs.
Reading specs from /usr/lib/gcc/avr/4.9.2/device-specs/specs-avr2
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.9.2/lto-wrapper
Target: avr
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-libssp --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr CFLAGS='-g -O2 -fstack-protector-strong -Wformat ' CPPFLAGS=-D_FORTIFY_SOURCE=2 CXXFLAGS='-g -O2 -fstack-protector-strong -Wformat ' FCFLAGS='-g -O2 -fstack-protector-strong' FFLAGS='-g -O2 -fstack-protector-strong' GCJFLAGS='-g -O2 -fstack-protector-strong' LDFLAGS='-Wl,-Bsymbolic-functions -Wl,-z,relro' OBJCFLAGS='-g -O2 -fstack-protector-strong -Wformat ' OBJCXXFLAGS='-g -O2 -fstack-protector-strong -Wformat '
Thread model: single
gcc version 4.9.2 (GCC)
_______________________________________________
AVR-GCC-list mailing list
address@hiddenhttps://lists.nongnu.org/mailman/listinfo/avr-gcc-list