I had a problem using TIMER2 interrupts, because tone library already
occupies it. Even when I do not include that library. I fixed it by
modifying Tone.cpp code with the weak attribute. Now your code
can reuse the interrupt vector. Of course tone() is now unavailable.
This would be a good practice for all base library ISR vectors.
ISR(TIMER2_COMPA_vect) attribute ((weak));
You can do this by editing and recompiling your project. Arduino IDE
seems to take care of recompilation of the modified tone.cpp
/Applications/Arduino/Contents/Resources/Java/hardware/cores/arduino/Tone.cpp
Not the OP, but I have also found I cannot redefine ISRs in my sketches, I assumed this was normal, are you suggesting that we should expect to be able to override INT0 etc ?
The two USART ones didn't work with 4.3.2 but they did with 4.7.1, and the TIMER0_OVF one didn't work on either of them.
It would definitely make sense to make the functions weak. I tried it and it made the above sketch compile with everything uncommented. I think it should be a goal of arduino to be able to use any program that don't use arduino libraries in the IDE, and that means being able to redefine the ISRs.
I had problems in compilation using TIMER0_OVF and the following code and was going crazy as it worked ok using the code below:
void setup() {
bitSet(DDRB, 5); // Pin 13 as output
TCCR0A = 0; TCCR0B = 1<<CS02 ; bitSet(TIMSK0, TOIE0);
}
void loop() { }
ISR(TIMER0_OVF_vect) {
bitSet(PINB, 5); // toggle pin 13
}
The error was C:\arduino-1.0\hardware\arduino\cores\arduino/wiring.c:49: multiple definition of `__vector_16'
However, the next lines compile (and run) ok
void setup() {
bitSet(DDRB, 5); // Pin 13 as output
TCCR1A = 0; TCCR1B = 1<<CS12 ; bitSet(TIMSK1, TOIE1);
}
void loop() { }
ISR(TIMER1_OVF_vect) {
bitSet(PINB, 5); // toggle pin 13
}
Now I've seen the comment two posts above ( and the TIMER0_OVF one didn't work on either of them )and felt some relief. Thanks a lot wizenedEE