user79960: In my project Pin 3 of Arduino UNO is as External interrupt (INT1) and at the same time, I have to run Timer2. INT1 dosen't work When Timer2 is run. Timer2 is run just as timer. Is it my mistake or it is logical?
I connect a key to pin 3 as external interrupt and also run timer. Every time INT1 on pin 3 senses rising edge Button_ISR() is called.
but because of running timer2, Button_ISR() is not called.
THis is my code:
int buttonPin = 3;
void setup()
{
  pinMode(buttonPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(3), button_ISR, RISING);
  Serial.begin(9600);
  TCCR2B = 0x07; // clock frequency / 1024
  //OCR2B = 0x00;  // Output compare
  TCNT2 = 0;     // Set counter 2 to zero
  TIMSK2 = 0x01; // Enable overflow interrupt

}

void loop()
{

}


void button_ISR()
{
  Serial.print("button_ISR()");
  Serial.print("\n");
}


user31668: Here are my 2 cents:
Your code is missing the handler for the timer. You have enabled the Timer overflow interrupt, but you have ISR prepared for it. So, the control is ending up reaching unhandled interrupt ISR which is a Restart
Arduino is restarting all the time.
Adding one line should fix it temporarily.
ISR(TIMER2_OVF_vect) {}

Here is the updated code. I can see that the code is now running (not restarting at least)
https://wokwi.com/arduino/projects/307835582788141632
    int buttonPin = 3;
    void setup()
    {
      pinMode(buttonPin, INPUT_PULLUP);
      Serial.begin(9600);
      Serial.println("ready!");
      TCCR2B = 0x07; // clock frequency / 1024
      //OCR2B = 0x00;  // Output compare
      TCNT2 = 0;     // Set counter 2 to zero
      TIMSK2 = 0x01; // Enable overflow interrupt
      attachInterrupt(digitalPinToInterrupt(3), button_ISR, RISING);
    
    
    }
    
    void loop()
    {
    
    }

void button_ISR()
{
  Serial.print("button_ISR()");
  Serial.print("\n");
}

ISR(TIMER2_OVF_vect) {}


Here is the disassembly code found on the Wokwi Arduino simulator for your sketch

and if you see the location  0xf6:

you will see that the code is doing a soft reset ( JMP 0). I hope this is helpful to you. Please feel free to ask if you have any questions.

79960: <p>In my project Pin 3 of Arduino UNO is as External interrupt (INT1) and at the same time, I have to run Timer2. INT1 dosen't work When Timer2 is run. Timer2 is run just as timer. Is it my mistake or it is logical?</p>
<p>I connect a key to pin 3 as external interrupt and also run timer. Every time INT1 on pin 3 senses rising edge Button_ISR() is called.
but because of running timer2, Button_ISR() is not called.</p>
<p>THis is my code:</p>
<pre><code>int buttonPin = 3;
void setup()
{
  pinMode(buttonPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(3), button_ISR, RISING);
  Serial.begin(9600);
  TCCR2B = 0x07; // clock frequency / 1024
  //OCR2B = 0x00;  // Output compare
  TCNT2 = 0;     // Set counter 2 to zero
  TIMSK2 = 0x01; // Enable overflow interrupt

}

void loop()
{

}


void button_ISR()
{
  Serial.print(&quot;button_ISR()&quot;);
  Serial.print(&quot;\n&quot;);
}
</code></pre>
 31668: <p>Here are my 2 cents:</p>
<p>Your code is missing the <code>handler</code> for the timer. You have enabled the Timer overflow interrupt, but you have ISR prepared for it. So, the control is ending up reaching unhandled interrupt ISR which is a <code>Restart</code></p>
<p>Arduino is restarting all the time.</p>
<p>Adding one line should fix it temporarily.</p>
<pre><code>ISR(TIMER2_OVF_vect) {}
</code></pre>
<p>Here is the updated code. I can see that the code is now running (not restarting at least)</p>
<p><a href="https://wokwi.com/arduino/projects/307835582788141632" rel="nofollow noreferrer">https://wokwi.com/arduino/projects/307835582788141632</a></p>
<pre><code>    int buttonPin = 3;
    void setup()
    {
      pinMode(buttonPin, INPUT_PULLUP);
      Serial.begin(9600);
      Serial.println(&quot;ready!&quot;);
      TCCR2B = 0x07; // clock frequency / 1024
      //OCR2B = 0x00;  // Output compare
      TCNT2 = 0;     // Set counter 2 to zero
      TIMSK2 = 0x01; // Enable overflow interrupt
      attachInterrupt(digitalPinToInterrupt(3), button_ISR, RISING);
    
    
    }
    
    void loop()
    {
    
    }

void button_ISR()
{
  Serial.print(&quot;button_ISR()&quot;);
  Serial.print(&quot;\n&quot;);
}

ISR(TIMER2_OVF_vect) {}
</code></pre>
<hr />
<p>Here is the disassembly code found on the Wokwi Arduino simulator for your sketch</p>
<p><a href="https://i.stack.imgur.com/D0b0G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D0b0G.png" alt="enter image description here" /></a></p>
<p>and if you see the location <code> 0xf6</code>:
<a href="https://i.stack.imgur.com/0oenN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0oenN.png" alt="enter image description here" /></a></p>
<p>you will see that the code is doing a soft reset ( <code>JMP 0</code>). I hope this is helpful to you. Please feel free to ask if you have any questions.</p>
