Elegant way to prevent same interrupt within ISR? (Teensy 4.1)

rmac

Member
Hi,

in a current T4.1 project I came across the following problem:
While an ISR (triggered by a GPIO falling edge) is running and the same interrupt/edge appears, the ISR is not immediately triggered (= interrupted) again (as I expected),
but it seems that the ISR is immediately executed a second time after the first run ends. As if the second event is saved until the running ISR ended.

Background:
In the ISR SPI1 is used to request data from an external ADC, which sends data over the same pin that is observed by the edge triggered ISR. So while ISR is reading data,
the falling edge appears several times.

I've played around with noInterrupt()/interrupt() and cli()/sei() but this did not help. In the end I successfully used detachInterrupt()/attachInterrupt() inside the ISR.

Question: is there any better (= more elegant) way to solve this (except detachInterrupt/attachInterrupt) ?

Thanks in advance
 
short answer:
one of the first statements in ISR is to clear this particular interrupt, otherwise it can trigger again.
 
Yes, thanks...

...but what is the best/most elegant way to clear a particular interrupt?

Manipulating Interrupt masks or vector tables?
Using detach/attach?
 
Yes, thanks...

...but what is the best/most elegant way to clear a particular interrupt?

Manipulating Interrupt masks or vector tables?
Using detach/attach?

Sorry, I don't know if there is best/most elegant way. I have seen and done it a few different ways, like:

In the ISR, disable the ISR, then in your processing code, do your stuff and then re-enable it. BUT: in addition to this you may have to clear the status out, for any events that
happened while processing the previous interrupt.

I have also seen (and used), something like a busy variable in volatile memory, That I set (or external code sets) to say I am busy, and I maybe either just set a flag that an interrupt happened,
and/or ignore the interrupt, depending on the circumstances.
 
The most elegant way depends on what you consider elegant.

Some people value platform independence. They consider code which can run on any board to be the most elegant, even if it incurs overhead by calling various API functions. Others define elegance in pretty much the opposite way, desiring the fastest possible technique directly utilizing low-level hardware resources, sometimes with a secondary goal of smaller code in additional to highest possible performance. Still others mostly value the appearance of their source code, with a general attitude that the thing which really matters most is source code readability and long-term maintainability either by themselves or others who aren't familiar with the code. Among this 3rd group, what code style they consider elegant varies quite a lot.

Background:
In the ISR SPI1 is used to request data from an external ADC, which sends data over the same pin that is observed by the edge triggered ISR. So while ISR is reading data,
the falling edge appears several times.

This might be easier to discuss if you show us a program with the actual code (in a small but complete program which actually compile and runs properly if the ADC is present), and also mention which specific ADC you're using (datasheet link would be ideal) and any other important details of how it is really connected to Teensy. Details matter. For example, from only the description I can't even imagine which specific pin your using for attachInterrupt.
 
Back
Top