T
T
Tw1ce2019-02-16 03:50:45
Arduino
Tw1ce, 2019-02-16 03:50:45

How not to postpone interrupt processing indefinitely?

If I disable the processing of this interrupt in the interrupt code, for example, for a couple of seconds, then the interrupt will indeed not be processed for these two seconds, but if it was, it will be processed immediately after the next interrupt is connected. Do I understand correctly that the microcontroller remembers the fact of the interrupt, and since my vector is the only one for this processing, and it is turned off, it cannot throw off this flag until I just turn on the interrupt again and it immediately joyfully passes it to me? Is there any way to override this behavior? Or throw off this flag in some other way? At some point, I want to completely disable processing, so that if there were interruptions during the absence of the handler (as I understand they always exist), then I don’t need to report them.

volatile bool interrupt;
bool process;

void isr() {
  interrupt = true;
  digitalWrite(13, HIGH);
  delayMicroseconds(10000);
  digitalWrite(13, LOW);
}

void setup() {
  pinMode(3, INPUT_PULLUP);
  attachInterrupt(1, isr, FALLING);
}

void loop() {
  if (interrupt) {
    detachInterrupt(1);
    interrupt = false;
    process = true;
  }
  if (process) {
    delay(2000);
    process = false;
    attachInterrupt(1, isr, FALLING);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-02-16
@Tw1ce

If I disable the processing of this very interrupt in the interrupt code, for example, for a couple of seconds, then the interrupt will indeed not be processed for these two seconds, but if it was, it will be processed immediately after the next interrupt is connected.

This description is only valid for an edge-triggered interrupt. The interrupt triggered by the signal level is not stored anywhere. Regardless of whether it was requested at the time it was disabled, if it is not requested at the time the interrupt is enabled, no interrupt will occur.
True for edge-triggered interrupts. False for level triggered interrupts.
Not true in general. Interrupt request flags can be accessed through registers, sometimes these registers can be cleared by software.
Some interrupts can be configured to trigger on level or edge. For example, Atmel can configure how external interrupts INT0 and INT1 are detected by the EICRA register.
Again, on Atmel, the external interrupt flags are in the EIFR R/W register, the appropriate bits of which can be written to 0 to clear the stored interrupt request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question