AVR stable variable

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can I declare a stable variable which does not lost data even in case of power of?
Also I want to change this variable in any time without lost data and force me to set up again even the mcu turned off.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

giorgos3924 wrote:
How can I declare a stable variable which does not lost data even in case of power of?
Also I want to change this variable in any time without lost data and force me to set up again even the mcu turned off.

http://www.nongnu.org/avr-libc/u...

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Check into using EEPROM.

 

In consideration of others, please RTFM!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Declaration of variable in combination with data of eeprom it's necessary?
Each time that I read the eeprom it's must to put the data(of eeprom) in some variable in my program?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't want to declare a variable, in this case just for haven't commitment in memory.
It is possible? TO manage a position of eeprom without to draw the data in some variable.
Or something like that it's must be?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

giorgos3924 wrote:
Declaration of variable in combination with data of eeprom it's necessary?
Each time that I read the eeprom it's must to put the data(of eeprom) in some variable in my program?
With AVR GCC, yes. Some other compilers provide a more seamless experience with EEPROM-based variables.

int EEMEM foo_in_EE;

int main(void) {

  int foo_in_SRAM;

  foo_in_SRAM = eeprom_read_word(&foo_in_EE);
  
  foo_in_SRAM = do_some_stuff(foo_in_SRAM);
  
  eeprom_update_word(&foo_in_EE, foo_in_SRAM);

}

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

giorgos3924 wrote:
a stable variable which does not lost data even in case of power of?

The term you're looking for is "non-volatile" or, perhaps, "persistent"

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Each time that I read the eeprom it's must to put the data(of eeprom) in some variable in my program?

Well that part is not true. It's quite possible to write something like:

PORTB = eeprom_read_byte(&eevar) ;

Which involves no intermediate variable (the compiler will just read to R24 then write to the port).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using avrstudio 6.1
I'll try to do with eeprom read/write functions and eeprom.h maybe.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Was there a question in that?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Its a simple concept. The user chooses the value he wants, it gets written to eeprom for later, and also stored in a ram variable. I use the same name but add ee to the eeprom name. When you turn the avr off then on, it restarts, refreshes the ram var from eeprom, and you are back in business with the value you saved before.

Imagecraft compiler user