1

I'm writing a C program for ATmega64A which has a INT0 ISR. This ISR should be executed in case of INT0 falling edge OR if the TIMER3 goes overflow.

To avoid doubling the code I'd like to trigger Int0 ISR in the Timer 3 overflow ISR.

Unfortunately there is no such information in the datasheet. At least in the INTF register description section:

enter image description here

Does anyone tries this? Or maybe someone knows this in theory?

Roman Matveev
  • 2,942
  • 7
  • 32
  • 75

1 Answers1

3

Nope.

Writing a 1 to the flag will clear it. Writing a 0 will do nothing.


However, if you are using avr-libc and want to have two (or more) vectors having exactly the same code, this is possible. You use interrupt aliasing. An example (from here):

ISR(PCINT0_vect){  
    ...  
    // Code to handle the event.
}

ISR(PCINT1_vect, ISR_ALIASOF(PCINT0_vect));

In this example both PCINT0 and PCINT1 will share the same interrupt code - both entries in the vector table will point at the same function. This may be sufficient for your needs.

Tom Carpenter
  • 63,168
  • 3
  • 139
  • 196
  • So is there any solution for such task (run one code from several ISR's)? – Roman Matveev Jul 20 '16 at 12:36
  • @RomanMatveev see my edit - I had to go look up the syntax. – Tom Carpenter Jul 20 '16 at 12:39
  • 1
    ... or you could just create each ISR as a shell (wrapper) that calls a common sub-function. – Dave Tweed Jul 20 '16 at 12:43
  • @DaveTweed that can be done, but calling functions from ISRs is not always a good idea at least with `avr-libc`/`avr-gcc`. It can result in extra overhead from additional registers being pushed and popped, and also adds overhead from the call/ret instructions. Aliasing if available is a nice clean method which results in zero overhead on top of the original interrupt routine. – Tom Carpenter Jul 20 '16 at 12:46
  • Aliasing has it's own disadvantage: ISR's should be EXACTLY the same. So I can't do INT0 ISR and timer register clear from Timer ISR in the same time. – Roman Matveev Jul 20 '16 at 12:54
  • @RomanMatveev what are you trying to clear? If it is just the flags, they self-clear. Otherwise using DaveTweeds suggestion is the only simple way you'll do it if you want each to do different things. – Tom Carpenter Jul 20 '16 at 13:05
  • Tom, I speak about timer counter register (TCNT) clear. It is an artificial example (as TCNT shouldn't be cleared actually). Moreover I thought about triggering the INT0 ISR by changing the pin state. Will it work? – Roman Matveev Jul 20 '16 at 19:10
  • @RomanMatveev I believe that changing the output register should trigger the ISR, but not 100% sure. – Tom Carpenter Jul 20 '16 at 19:30