Correctly using multiple interrupts

Hi all.
I am using Arduino IDE and ESP32.

For my project I need to use several external interrupts.

What are the correct practices when using multiple ext interrupts?
How do I allocate priority?
How to stop conflict?

I would really appropriate your input.
Regards

What do you mean with "external" interrupts? :thinking:

Anyway, I think you need to read some documentation, like THIS. Otherwise, you need to make some example and/or describe what kind of interrupt you need to manage (e.g. source? event type and duration?).

Hi. Thank you for the reply.
External interrupts are caused by external events, like a pin changes from HIGH to LOW.
In my project I need to monitor several of these events.

Regards

isn't the priority based on which interrupt occurs first? would you expect a "higher priority" interrupt to interrupt an interrupt in progress (do you really have such a need)?

interrupts should be written to do a little as necessary and rely on the foreground code to do the work requested by the interrupt unless some response must be performed quickly.

Hi. Thank you for the reply.
Yes, looks like the ESP32 has no priorities with interrupts.
(In the old CPUs it was possible to set some priorities.)

So it is First-Come-First Served basis.
I am new to the ESP32, and I am still learning.

Thank you
Regards

Yep, that's the common situation. I just mean except for particular purpose, there's no need to specify "external". :wink:

Ok, but I still don't get the point. Did you read the page I linked you before, describing interrupts on ESP32?

Even if it depends on the kind of interrupt handling you have in your mind, you could just easily implement such kind of behavior using a few global (volatile) variables as semaphores.

As an example, if an interrupt has higher priority, meaning any other must be "masked" away, just set the semaphore to "true" while serving the interrupt, so any other subordinate interrupt routine can just avoid to execute the ISR code with a simple "if (semaphore) return;" as its first statement. Can't be more specific without a detailed desired interrupt handling description.

1 Like

If you decide to use the pin-change interrupt, when you read the pins you are interested in, you set the priority your self. The order of reading the pins to find the first changed pin will be your priority order.

Hello Francesco2017

Take a view here to design a "software" interrupt.

Have a nice day and enjoy coding in C++.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.