samm_flynn
Well-known member
Context:
I have a timer interrupt running at 1 kHz that performs calculations. For these calculations, I need 6 float values, which are received over USB serial. The serialEvent() function (called at over 7 MHz) assigns values to these 6 floats. Given that the Teensy 4.1 is a 32-bit microcontroller and each float assignment takes 1 cycle(I am assuming), there’s a risk that the timer interrupt might trigger in the middle of these assignments. This would result in unsynchronized data being used in the timer callback.
Question:
How can I ensure that the 6 float assignments occur atomically—that is, without a timer interrupt occurring in the middle of the assignment process? Specifically, if I disable interrupts around the assignment block (using something like noInterrupts(); assignment(); interrupts(), will the timer interrupt be queued and executed after interrupts are re-enabled, or will it be completely skipped?
Are there any way to read variable inside the interrupt safely? Is there a special way to do this?
I have a timer interrupt running at 1 kHz that performs calculations. For these calculations, I need 6 float values, which are received over USB serial. The serialEvent() function (called at over 7 MHz) assigns values to these 6 floats. Given that the Teensy 4.1 is a 32-bit microcontroller and each float assignment takes 1 cycle(I am assuming), there’s a risk that the timer interrupt might trigger in the middle of these assignments. This would result in unsynchronized data being used in the timer callback.
Question:
How can I ensure that the 6 float assignments occur atomically—that is, without a timer interrupt occurring in the middle of the assignment process? Specifically, if I disable interrupts around the assignment block (using something like noInterrupts(); assignment(); interrupts(), will the timer interrupt be queued and executed after interrupts are re-enabled, or will it be completely skipped?
Are there any way to read variable inside the interrupt safely? Is there a special way to do this?