Search code examples
avratmel

Is it possible to save some data parmanently in AVR Microcontroller?


Well, the question says it all. What I would like to do is that, every time I power up the micro-controller, it should take some data from the saved data and use it. It should not use any external flash chip. If possible, please give some code-snippet so that I can use them in AVR studio 4. for example if I save 8 uint16_t data it should load those data into an array of uint16_t.


Solution

  • You have to burn the data to the program memory of the chip if you don't need to update them programmatically, or if you want read-write support, you should use the built-in EPROM.

    Pgmem example:

    #include <avr/pgmspace.h>
    
    PROGMEM uint16_t data[] = { 0, 1, 2, 3 };
    
    int main()
    {
         uint16_t x = pgm_read_word_near(data + 1); // access 2nd element
    }