Interrupts in arduino Yun

Hi

I have a problem with Interrupts in arduino Yun.
As I understand: after interrupt (interrupt is performed when it detects a rising edge) processor should continue the main program but in my case it is not.
When I press the button interrupt is executed and program "hangs" in this interruption, does not return to the loop ().Only after releasing the button, program is return to main loop().

My code looks something like this:

volatile int count = 0;

void setup()
{
   attachInterrupt(0, inc, RISING);                                                            
}


void loop()
{

   // Here a few functions that should be performed cyclic

}

void inc()                                            //interrupt function 
{
   count = count + 1;                            //variable is incremented and the program "hangs"
                                                        // at this point, does not return to the loop ();
                                                        //until I release the button
}

I would ask for help / explanation of why this can happen.

I tried your code, I put a blinking led in the loop and it works normally. Maybe some problem with the circuit? What do you have in the loop?

Program is large.
Supports: display, rtc, keyboard and telnet, and a few other things.
The new project actually works.
Is there a possibility that one of the libraries uses the interrupt and breaks something?
Of course, I don't use delay ();

It is possible but guessing without any code is very hard :slight_smile:
Is something else connected to that pin? Is it shared between different libraries?

Ok, I found the problem. Interrupt stops working when I use this function:

void getDate()
{
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);

  second = bcdToDec(Wire.read());
  minute = bcdToDec(Wire.read());
  hour = bcdToDec(Wire.read() & 0b111111); 
  weekDay = bcdToDec(Wire.read()); 
  monthDay = bcdToDec(Wire.read());
  month = bcdToDec(Wire.read());
  year = bcdToDec(Wire.read());
}

The function reads the date and time from the RTC.

Don't call that function inside an interrupt.

Interrupt routines must be shorter as possible and no complex code has to be executed inside an interrupt function. Inside an interrupt you can't listen for another interrupts and the Wire class rely on interrupts.

So if you use the Wire library inside an interrupt it wont work.

No, of course, I did not call this function inside the interrupt. Interrupt only increments the variable.
The function is called in the loop ().

You say execution doesn't return until the button is released. How many times does the counter get incremented?

While you are configuring rising edge interrupts, it almost seems like it's getting switched to level sensitive interrupts: this would mean that the interrupt service routine would keep re-entering over and over as long as the input is active. The side effect of this is that the counter would be incremented MANY times, hence my initial question.

Counter is incremented only once.
The interesting thing is that if I don't use anywhere getDate() function, everything works !

Do you use Wire in other functions?