Help: volatile variable versus volatile array for ISR access
2007-11-03 by Larry Barello
Maybe the problem isn't volatile, but rather a race condition where the ISR is modifying something your foreground code is using? It isn't sufficient to tag something volatile, you also need to prevent the ISR from corrupting the data during your operation. Volatile just tells the compiler to not optimize access to the variable since it may change its value. Indeed, volatile may not even be needed if you enclose the entire routine using the variable in a CLI/SEI to prevent the interrupt handler from mucking things up. If the ISR doesn't re-enable interrupts, it can optimize access as much as it likes, same for foreground code. Volatile is needed, however, for any *external* event, like I/O port operation where things happen completely beyond the control of the processor (or more precisely, outside of the CPU state machine operation). Cheers!
Show quoted textHide quoted text
-----Original Message----- From: AVR-Chat@yahoogroups.com [mailto:AVR-Chat@yahoogroups.com] On Behalf Of Cat Sent: Saturday, November 03, 2007 12:21 AM To: AVR-Chat@yahoogroups.com Subject: Re: [AVR-Chat] Help: volatile variable versus volatile array for ISR access Hi Robert, I didn't say there's any pointer. Except maybe that the name of an array is a pointer. I only use "volatile" to make a variable modifiable from an ISR. And it works, except for arrays. Thanks, Cat