interrupt priority Arduino DUE

Hi there Im using 4 software interrupts I would like now to use an extenal hardware interupt as an emenrgency button.

Can I change or set the proprity of the interrupts ??

Can I change or set the proprity of the interrupts ??

No. The priority is defined in the hardware.

Since an interrupt is supposed to be handled quickly, you should not need to mess with the priority. That you think you need to suggests that your interrupt handlers are not quick. It is far more important that you fix that, or quit misusing interrupts, than it is to diddle with the priority.

Hi thanks for your reply

the ASF Atmel Software Framework offers

NVIC_SetPriority(TWI1_IRQn, 0)

I just want to use the same at my arduino due borad to set the highest priority for my hardware emegergency botton interrupt

I hope that you got what I mean

Why bother? It sounds like the vast majority of time taken will be that expended by the operator deciding to push the emergency stop. You could be polling the button, and provided you haven't used delay in your code, it'll be blazingly fast.

Or is the emergency stop being triggered by the arduino too?

My Emergency Stop is a soft stop.. so it just will deactivate all the interupts when the user push a button ( Hardware Interrupt)

and I saw that ASF provides in the NVIC header (Nested Vektor Interupt Control)

a priority choice for the interupts handler so I can decide which interuptshandler shall have a high piority through

NVIC_SetPriority(firstHandler, 0);
Im just wondering if can apply the same under Arduino DUE

Im just wondering if canĀ  apply the same under Arduino DUE

I'm just wondering when you are going to take the hint and POST YOUR CODE!

Well, enough hinting. POST YOUR CODE.

You are almost certainly using interrupts incorrectly. Processing the "emergency stop button" (a switch seems far more useful than a button) after the current serial byte has been received or after the current clock tick has happened doesn't REALLY seem like it is going to cause that much difficulty.

After all, some human has seen a problem, decided that something needs to happen, and slapped the switch. Reacting to that within nanoseconds then seems silly.

A good reason to use an interrupt for an emergency stop switch is to guarantee that it
will be noticed, not to notice it with microsecond accuracy (which isn't a good reason).

This means that only the interrupt handler has to be correct for the emergency stop actions
to work as expected - if you poll the entire code of the sketch has to be correct and real-time
which isn't as plausible.

DUEDUE:
and I saw that ASF provides in the NVIC header (Nested Vektor Interupt Control)

a priority choice for the interupts handler so I can decide which interuptshandler shall have a high piority through

NVIC_SetPriority(firstHandler, 0);
Im just wondering if can apply the same under Arduino DUE

Sure. Use that exact same function even. Just call NVIC_SetPriority with the proper interrupt and priority and it'll work. The only catch is that you need to figure out the proper value for the interrupt you're interested in. This can be found within the Arduino core source code or you can look it up in the ASF documentation.

Reviving this old topic because it's at the top of Google search results on interrupt priority. According to the SAM3X8E manual, configuring interrupt priorities is in fact possible on Due, but I have not figured out how to set it up yet.

I'm gonna run an ADC at high speed, and I need to make sure ADC nor DMA will be interrupted by other peripherals attached to the same CPU (SPI, serial communication, possibly I2C).

With the ADC peripheral, there is only a PDC DMA, therefore the only interrupt priority to take into account is the one of the ADC.

If you want the ADC interrupt handler to have the highest priority above all other interrupt handlers, set its priority level to 0 (= the highest priority: NVIC_SetPriority(ADC_IRQn, 0)), and all other interruptions with a higher number ( from 1 to 15 for a lower priority level ). Note that SysTick priority level is concerned too.

I did not realize "NVIC_*" functions are available with the Arduino framework, thought I will need to access the registers directly. Thanks a lot!

I wonder if I need to manually move all the other priorities out of the way, or if just setting 0 for ADC_IRQn is enough?

The default priority level of all interrupt handlers are set to 0 on a DUE.