What could cause corrupted variables or code failure when I am using interrupts?
If you have a variable used in both main-line and interrupt code, make sure it is qualified “volatile”. This will prevent the compiler from using cached copies of the variable and performing other optimizations. The compiler will also attempt to access the variable atomically, but this is not always possible if the assembly instruction set does not permit this. You can check the assembly list file to see the assembly code used to access variables and determine if the access is atomic. If it is not, consider disabling the interrupts when it is accessed in main-line code.