Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Using Volatile keyword in embedded code

Volatile is probably the least documented keyword in most tutorials and books. This is the primary cause of most misuses and bugs related to it. If you already are programming microcontrollers, you probably know that volatile is always used on global variables that are accessed from interrupt service routines. Otherwise code won’t work. After few requests I decided to drop few lines about volatile keyword. This keyword is commonly used to tag memory type. We hear “volatile memory”, “non-volatile memory” when talking about computer hardware. As quick reminder – “non-volatile memory” is type of memory that stores its contents even when power is off. Such type of memory is EEPROM, Flash, FRAM. This is easy from hardware perspective. But what volatile keyword means in C or C++ code? This is… Continue reading