Do interrupts interrupt other interrupts on Arduino?

后端 未结 3 1986
别跟我提以往
别跟我提以往 2021-02-06 23:51

I have an Arduino Uno (awesome little device!). It has two interrupts; let\'s call them 0 and 1. I attach a handler to interrupt 0 and a differ

3条回答
  •  长情又很酷
    2021-02-07 00:25

    On Arduino (aka AVR) hardware, nested interrupts don't happen unless you intentionally create the conditions to allow it to happen.

    From avr-lib:

    The AVR hardware clears the global interrupt flag in SREG before entering an interrupt vector. Thus, normally interrupts will remain disabled inside the handler until the handler exits, where the RETI instruction (that is emitted by the compiler as part of the normal function epilogue for an interrupt handler) will eventually re-enable further interrupts. For that reason, interrupt handlers normally do not nest. For most interrupt handlers, this is the desired behaviour, for some it is even required in order to prevent infinitely recursive interrupts (like UART interrupts, or level-triggered external interrupts). In rare circumstances though it might be desired to re-enable the global interrupt flag as early as possible in the interrupt handler, in order to not defer any other interrupt more than absolutely needed. This could be done using an sei() instruction right at the beginning of the interrupt handler, but this still leaves few instructions inside the compiler-generated function prologue to run with global interrupts disabled.

    (source: http://linux.die.net/man/3/avr_interrupts )

提交回复
热议问题