4.6.5 What Can Cause Corrupted Variables and Code Failure When Using Interrupts?
This is usually caused by having variables used in 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 the following section of this user’s guide:
4.4.3 How Do I Share Data Between Interrupt and Main-line Code?