Describe the difference between volatile and non-volatile memory in a microcontroller. What is each type used for, and what trade-offs matter in practice?
Volatile memory requires power to retain its contents. In microcontrollers, this usually refers to RAM, which stores temporary data such as stack frames, heap allocations, and runtime variables.
counter = 0 # Stored in RAM while the program is running
Non-volatile memory keeps data even when power is removed. In microcontrollers, this is commonly flash memory, EEPROM, or ROM, and it stores firmware, calibration values, and persistent configuration.
// Firmware image is stored in flash and loaded after reset
Volatile memory is typically faster to read and write and supports frequent updates. Non-volatile memory is slower to write, may require erase cycles, and often has limited write endurance.
Code and persistent settings usually live in non-volatile memory, while actively changing program state lives in volatile memory. This separation helps balance speed, persistence, and hardware limits.
You are practicing as a guest. Sign up free to get your answer graded with AI feedback. Your draft stays right here.