The Arduino page for noInterrupts() says:

Some functions will not work while interrupts are disabled, and incoming communication may be ignored.

While it may not be possible to give a complete listing of what would be disabled, having an incomplete list of functions which definitely are disabled would be useful.

I was thinking of calling a DHT sensor library which internally uses millis() while interrupts were disabled to avoid both bit banging and servicing interrupts simultaneously if possible (the interrupt would hold and be processed after).

Which functions are definitely disabled when interrupts are disabled?

What about incoming communication? My guess is that it would be slightly worse on the ATmega32U4 (eg Leonardo) as the one processor does USB and everything else as well.

  • 2
    The following command grep ISR *.cpp will generate a list of all ISR functions in the Arduino core. These are the HardwareSerial (UART/USB: receive, transmitt) and Timer functions (millis, micros, tone). – Mikael Patel Feb 13 '19 at 7:53

From what I found turning off interrupts will definitely disable incrementing values of micros() and millis() This means that also every method that uses them like delay() will also not work correctly.

Of course manually attached interrupts using attachInterrupt() will also not work as intended.

According to comments by @Juraj Things that also will not work are Serial interrupts. Also libraries like Wire require interrupts for their logic.

EDIT: @EdgarBonet You are right, I removed incorrect info.

  • Serial receive is handled with interrupt for hardware Serials (including native USB) and software Serials – Juraj Feb 13 '19 at 10:36
  • Wire library send and receive is implemented in an interrupt – Juraj Feb 13 '19 at 10:44
  • 1
    The PWM you get from analogWrite() is not handled by interrupts: it's generated by the timers themselves. – Edgar Bonet Feb 13 '19 at 11:27

SPI.transfer() also uses interrupts - but you can 'manually' wait them out to know when to proceed. For example, I had a program where I needed to send out 45 bytes in 50uS (20KHz refresh rate). During testing, I kept seeing jitters in the datastream - about every 4uS if I recall. The micros() interrupt time. Turned off interrupts during the data burst and the jitter went away. So the command to send out a byte looked this, repeated 45 times (no for loop):

spdr = byte0; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
spdr = byte1; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
spdr = byte2; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
spdr = byte43; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
spdr = byte44; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;

So the transfer needed 17 clocks with the SPI clock set to 8 MHz. After the transfer I turned interrupts back on to wait for the next incoming signal edge to send out the next burst.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.