使用 noInterrupts() / interrupts() 块时哪些函数不起作用?

Which functions don't work when using a noInterrupts() / interrupts() block?

我在 Arduino 库中有一些时间敏感的代码,想在 noInterrupts() and interrupts() 之间保护它。文档指出:

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

是否有哪些(标准)功能不起作用的列表?特别是,我需要通过调用 millis() 来节省时间。 millis() 后面的数字是否仍在更新,或者我应该将其移出 noInterrupts() / interrupts() 块?

看起来 from this answer 尤其是 millis() 会通过禁用中断来禁用,因为该调用依赖于附加到定时器的中断,定时器在 时触发 1KHz。不过,我已经仔细阅读了官方文档,但没有找到可能受到影响的详尽列表。我敢肯定很多人对官方文档中明显缺乏这一点感到沮丧。

进一步看,控制millis()的定时器(ATmega文档中的Timer/Counter0)仍然在后台计数是否启用中断-- 问题是,如果您的代码跨越中断 触发的时间,您可能会错过一个滴答声 。请参阅下面的参考资料。

底线是,如果您需要中断,请保持 noInterrupts() 部分简短。并使附加到中断的代码更简短。 ;) 无论您是使用草图还是裸机编码,保持中断快速进出始终很重要。

这个 external reference is also interesting, shows the math and code behind the millis().