Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What could cause corrupted variables or code failure when I am using interrupts?

0
Posted

What could cause corrupted variables or code failure when I am using interrupts?

0

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123