0

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.

10 Rep
  • 2,217
  • 7
  • 19
  • 33
ponir
  • 447
  • 7
  • 20
  • 1
    Which AVR are you using? The memory resources are very different between devices, some have user sectors that are designed for storing calibration factors, serial numbers and the like. – uɐɪ Jun 26 '12 at 07:05
  • you received an answer including code which is correct, please accept it or respond why you are not happy with it. – John Apr 30 '14 at 13:25

2 Answers2

1

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
}
  • Actually, I'll need to save data programmatically. The thing is, I'll have to calibrate some data in a place use those data for several hours. I want to calibrate it once use it for several hours. So, calibrating it again and again does not look good. Running the microcontroller for all those hours doesnot look good either. :( – ponir Jun 15 '12 at 10:43
0

You need to get the datasheet for the part you are using. Microcontrollers like these typically contain at least a flash and sometimes multiple banks of flash to allow for different bootloaders while making it easy to erase one whole flash without affecting another. Likewise some have eeprom. This is all internal, not external. Esp since you say you need to save programatically this should work (remember how easy it is to wear out a flash do dont save unless you need to). Either eeprom or flash will meet the requirement of having that information there when you power up, non-volatile. As well as being able to save it programmatically. Googling will find a number of examples on how to do this, in addition to the datasheet you apparently have not read, as well as the app notes that also contain this information (that you should have read). If you are looking for some sort of one time programmable fuse blowing thing, there may be OTP versions of the avr, and you will have to read the datasheets, programmers references and app notes on how to program that memory, and should tell you if OTP parts can be written programmatically or if they are treated differently.

The reading of the data is in the memory map in the datasheet, write code to read those adresses. Writing is described in the datasheet (programmers reference manual, users guide, whatever atmel calls it) as well and there are many examples on the net.

old_timer
  • 69,149
  • 8
  • 89
  • 168