Hello
I am trying to program an ATtiny microcontroller, but it crashes when I add any interrupt routine; for instance, I compiled with avr-gcc the following code
If I connect two LED to PORTA.0 and PORTB.0 I should see them blinking, but all is silent. I tried to give the hex file to simavr, and I have a crash output. If i comment the ISR routine the program works (i have the PORTB LED blinking), and obviously the simulator doesn't give me any error.
Is the code wrong, or needs some special parameters to avr-gcc/avrdude to be compiled/loaded?
steinie44:
Why use a timer? Use millis() for that. If you do need a timer, try MsTimer2.h
It works with ATtiny, but just in milliseconds.
Nope, for my project I need the micro to call a function asynchronously than the main code.
fungus:
giuliof:
TCCR0A = _BV(COM0A1) | _BV(COM0B1) | ...;
If I connect two LED to PORTA.0 and PORTB.0 I should see them blinking
Nope. You told it to set the outputs LOW when the timer gets a compare match.
Maybe you want to toggle them instead (or something...)
Sorry, that was a residual of a previous PWM test that worked fine. OCR0A and OCR0B should not influence the rest of the code (i think). Anyway in this code TCCR0A can be left zero, the ISR function must be called when timer register goes overflow.
fungus:
Try calling it "TIMER0_OVF_vect" instead of "TIM0_OVF_vect"
Nothing, I get this warning from avr-gcc, and when i load it I have not changes.
warning: ‘TIMER0_OVF_vect’ appears to be a misspelled signal handler
I noticed that interrupt functions makes the micro crazy: if I comment them, leaving registers inizialised, the main program is executed.
OK. The name changes depending on which "ATtiny" you're using (which you're keeping secret). I'm guessing it's not a Tiny85 because you use PORTA. If you're getting an error then you probably picked the right name.
giuliof:
If I connect two LED to PORTA.0 and PORTB.0 I should see them blinking, but all is silent. I tried to give the hex file to simavr, and I have a crash output. If i comment the ISR routine the program works (i have the PORTB LED blinking), and obviously the simulator doesn't give me any error.
Is the code wrong, or needs some special parameters to avr-gcc/avrdude to be compiled/loaded?
I compiled your code in Atmel Studio for an attiny84A and it runs fine. I tried different CPU clock rates, 16MHz, 8MHz, and 1MHz. They all ran fine. The ISR LED blinks about half the speed of the loop LED @1MHz.