Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Using External and internal EEPROM in ATMEGA8

Status
Not open for further replies.

Briez

Member level 5
Member level 5
Joined
Nov 30, 2012
Messages
83
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,288
Visit site
Activity points
1,835
Hello,

-> I want to use internal EEPROM of ATMEGA8 as a non-volatile memory save equipment. I have one project which needs to store count value of variable as a permanently whether power is off. I read datasheet of it and found basic code for it. But when i make power off the value of variable becomes zero. Can anyone tell me how to use 512-byte eeprom memory of atmega8 as non-volatile save memory?

-> I am using avr studio 4 as debugger and compiler.
 

hi
how did you use eeprom in your code ?
first : #include <avr/eeprom.h>
then if you want to declare a variable that it must store on eeprom declare your variable like this:
Code:
//eeprom variable   
uint8_t EEMEM NonVolatileChar;
uint16_t EEMEM NonVolatileInt;
uint8_t EEMEM NonVolatileString[10];

then if you want read the variable in the first of your code in start up you can write like this:
Code:
int main(void) {
 uint8_t SRAMchar; 
SRAMchar = eeprom_read_byte(&NonVolatileChar);
 }
if you want to copy a data from eeprom to sram , do it like this :
Code:
void main(void) {
 uint8_t StringOfData[10]; 
eeprom_read_block((void*)&StringOfData, (const void*)12, 10); 
}

now when you want to change the value of variable on the other hand update it you have two way : with checking and without checking

1. you can change the variable without cecking that variable is changed , to do it :

Code:
int main(void) { 
uint8_t SRAMchar; 
eeprom_write_byte (&NonVolatileChar, SRAMchar); 
}

2.if you want to copy a data from sram to eeprom without checking that variable (in sram) is changed you can write :
Code:
int main(void) {
 uint8_t SRAMchar[20];
 void eeprom_write_block ((const void *)&NonVolatileString,(void *)&SRAMchar, 12);
 }
note : the last number in argument of above functions are the number byte that you want to copy it form source to destination.
 

Thank you so much alexan_e and mojtaba_led for help.........

I made simple program for use of eeprom and it works..........

But in datasheet there is written that u can write eeprom upto 1,00,000 cycles. and i want to use eeprom writing upto unlimited times. so what should i do?
 

To prolong the life of the eeprom use a rotating scheme and write in different positions each time so that you use the compete area of the eeprom.

You should also use update eeprom instead of write so that you don't write it when it already has the proper value.
 

But in datasheet there is written that u can write eeprom upto 1,00,000 cycles. and i want to use eeprom writing upto unlimited times. so what should i do?
i know two ways :
1. checking that the value of eeprom is changed or not before update it , to do it for example you can write :
uint8_t EEMEM NonVolatileString[20];
int main(void) {
uint8_t SRAMchar;
eeprom_update_byte (&NonVolatileChar, SRAMchar);
}
of course this way cuse to decrase the speed of the program.

2.use a circular buffer (O-buffer) in EEPROM for storing data in EEPROM.for more information visit AVR101: High Endurance EEPROM Storage
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top