Disabling timer interrupts only

Is there a way of disabling timer interrupts only. I know that cli() and sei() affects both timer and external interrupts. What I want to do is to disable the time interrupts alone i.e the microcontroller should respond to external interrupts. This is the function I am using to setup the interrupt: void interruptSetup() { // Initializes Timer2 to throw an interrupt every 2mS. TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO INTO CTC MODE TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz SAMPLE RATE TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND OCR2A sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED }

This interrupt is tied to an ISR. I have two other external interrupts

If you set TIMSK2 to 0 that will turn off OCIE2A: Timer/Counter2 Output Compare Match A Interrupt Enable

I set TIMSK2=0x02 to disable Timer2. But I am doing this within the ISR and the ISR stops execution at that point. I am in a total fix. I have a total of three interrupts in my system running on UNO R3. Two are external and one is internal(Timer 2). What I want to do is to disable the CPU from responding to Timer2 interrupts while the ISR associated with it is running and enable Timer2 when the ISR is done. cli() cannot be used as it disables all interrupts. I want the CPU to respond to the two external interrupts while the execution of ISR associated with Timer2 is going on. Plus the ISR of the external interrupt 1 should be able to interrupt the ISR of 2 and vice versa. I am really desperate for an answer.

I set TIMSK2=0x02 to disable Timer2.

Setting that bit ENABLES the Timer/Counter2 Output Compare Match A Interrupt

But I am doing this within the ISR and the ISR stops execution at that point.

Setting that register should not stop the rest of your ISR from executing.

What I want to do is to disable the CPU from responding to Timer2 interrupts while the ISR associated with it is running and enable Timer2 when the ISR is done.

All interrupts are disabled while the ISR is running. That is why ISR's should be SHORT.

To enable the other interrupts while the Timer/Counter2 Output Compare Match A Interrupt ISR is running you can start the ISR with:

TIMSK2 = 0; // Prevent further TIMER 2 interrupts sei(); // Enable global interrupts

and end the ISR with:

cli(); // Disable global interrupts TIMSK2 = 0x02; // Enable Timer/Counter2 Output Compare Match A Interrupt return;

Thanks TIMSK2=0x02 was a typo.

Thanks for your reply. In fact it did work. But I decided to stick on to the Timer One library for doing this. The detachInterrupt() function solved all my problems. Thanks anyway for adding some great knowledge.