3.6.9 What Can Cause Corrupted Variables and Code Failure When Using Interrupts?
This is usually caused by having variables used by both interrupt and main-line code. If the compiler optimizes access to a variable or access is interrupted by an interrupt routine, then corruption can occur (see 3.4.6 How Do I Share Data Between Interrupt and Main-line Code? for more information).