Quantcast
Channel: Using volatile in embedded C development - Electrical Engineering Stack Exchange
Browsing all 10 articles
Browse latest View live

Answer by user for Using volatile in embedded C development

Lots of technical explanations but I want to concentrate on the practical application.The volatile keyword forces the compiler to read or write the variable's value from memory every time it is used....

View Article



Answer by supercat for Using volatile in embedded C development

In the absence of a volatile qualifier, an object's value may be stored in more than one place during certain parts of the code. Consider, for example, given something like:int foo;int...

View Article

Answer by Lundin for Using volatile in embedded C development

There exist two cases where you must use volatile in embedded systems.When reading from a hardware register. That means, the memory-mapped register itself, part of hardware peripherals inside the MCU....

View Article

Answer by JimmyB for Using volatile in embedded C development

A definition of volatilevolatile tells the compiler that the variable's value may change without the compiler knowing. Hence the compiler cannot assume the value did not change just because the C...

View Article

Answer by kkrambo for Using volatile in embedded C development

In the code snippets presented in the question, there is not yet a reason to use volatile. It's irrelevant that the value of adcValue comes from an ADC. And adcValue being global should get you...

View Article


Answer by Goswin von Brederlow for Using volatile in embedded C development

The volatile keyword tells the compiler that access to the variable has an observable effect. That means every time your source code uses the variable the compiler MUST create an access to the...

View Article

Answer by vicatcu for Using volatile in embedded C development

The main use of the volatile keyword on embedded C applications is to mark a global variable that is written to in an interrupt handler. It's certainly not optional in this case. Without it, the...

View Article

Answer by Rev for Using volatile in embedded C development

"Global variable that changes directly from the hardware"Just because the value is coming from some hardware ADC register, doesn't mean that it is "directly" changed by hardware. In your example, you...

View Article


Answer by Damien for Using volatile in embedded C development

The behavior of the volatile argument largely depends on your code, the compiler, and the optimization done.There are two use cases where I personally use volatile:If there is a variable I want to look...

View Article


Using volatile in embedded C development

I have been reading some articles and Stack Exchange answers about using the volatile keyword to prevent the compiler from applying any optimizations on objects that can change in ways that cannot be...

View Article
Browsing all 10 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>