Background:
I need very repeatable interrupt execution timing for my own ISR in the Arduino environment. The Timer0 overflow interrupt is used by the Arduino core library to provide millis(). Occasionally, the condition that triggers my interrupt is met while the Timer0 overflow interrupt is being executed. By default, the AVR does not allow one interrupt to "interrupt" another. See this Nested interrupts question.
The Timer0 ISR blocks my ISR from executing until it completes. This delay can take up to 7 µs, which is unacceptable in my application. (I know!)
I do not require millis() in my application, so I tried disabling the Timer0 overflow interrupt like so inside void setup()
:
TIMSK0 = 0;
Gotcha: Unfortunately, that breaks the hardware serial functions. I have looked through the core library source, but I don't understand how the hardware serial methods depend on Timer 0.
Constraints: I want my sketch to compile and work with a standard Arduino distribution, so I only have control of what's in my sketch directory (not the Arduino directory) and Arduino sketches hide "includes" from you, so I'm not sure I can avoid the "HardwareSerial.h" inclusion.
Exact Question:
- How does the Serial class depend on Timer0?
- Is there a way to make calls to the "Serial" class work again without modifying the core libraries?
- In general, can I re-define methods of (or the whole of) a class that's defined elsewhere?