Interrupts are disabling after the first occours

Hi mates, I've lost a couple of hours to figure out why the sketch doesn't come out from a while loop, I'm waiting an interrupt there, I'me sure it comes and it works but while keeps there. On the interrupt routine I'm stetting true a global boolean, the while checks it bu tit doesn't change. I noticed that including a lcd.print in the while loop solves the problem, I wonder know why that!! the solution is for sure that lcd.prind enables back somehow the interrupts, and writing an interrupts(); instead of lcd.write does the work too..

Why interrupts get disabled? Which is the reason? Is Arduino concept pretending to enable back interrupts after the first occours? Why? Really illogic

Thank you for clearing me!

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press “Ctrl + A”. This will select all the text.
  • Press “Ctrl + C”. This will copy the selected text to the clipboard.
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

thank you for help, sorry in quick reply I don't have the code function, but it's very easy to paste:

on setup I have this
attachInterrupt(digitalPinToInterrupt(19), zero, RISING);

on loop:

while (!cross) {
interrupts(); //IF I DON'T PUT THIS IT HANGS ON WHILE, I can write a lcd.print (" "); and it works too
if (Valoreenc>0 & (tempo4>(Valoreenc*40))) {digitalWrite(52,LOW);} else {digitalWrite(52,HIGH);}
tempo3= micros(); tempo4=tempo3-tempo2;

at bottom:
void zero() {

is cross declared volatile?

Any variable that can be changed within an interrupt, but is read from outside the interrupt, must be declared volatile.

Otherwise the compiler will look at that, see that cross is not changed in the while loop, and optimize away accessing cross every iteration of the loop. declaring the variable as volatile will tell the compiler that it can't assume that the value of the variable won't be changed by an interrupt.

thank you, really useful post!
Anyway the instruction interrupts(); made difference, and I don't think that this instruction tells the compiler to consider in a different way the variable "cross".
For some reasons the interrupts where disabled, and it's needed to re enable them or use a lcd.print to solve the problem

Please post your full sketch or a minimal example that exhibits the behaviour; please use code tags when posting code.

Further, the & in below is a bitwise AND, not a logical AND. Is that the intention?

Valoreenc>0 & (tempo4>(Valoreenc*40))