We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Have you specified your capture_number as volatile?
I tried adding __IO and the problem has been resolvedBut why is the capture_number variable being optimized?
Because the compiler does not know that value of capture_number can change on external event (interrupt), so it presumes it's value will not change unexpectedly.You can check disassembly code to see what the compiler did, sometimes it will even throw out the code if it thinks it does nothing.