[AVR] Strange Problem with EEPROM of AVR Controller

Status
Not open for further replies.

tahertinu

Member level 4
Joined
Jun 11, 2011
Messages
74
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Ahmedabad
Visit site
Activity points
1,752
HI Everyone here. I am currently working on GSM project. i have interfaced GSM900 modem with AVR ATmega16 uC on UART pins. using EEPROM to store the NUMBERs of allowed persons. as of now Maximum Three numbers are stored. another string Named SLAVE is used to store slave string received from particular phone number.
Each Number and Each SLAVE is having Flages which are also stored to EEPROM. total 3 Numeber,3 Slaves,3 Number Flages, 3 Slave Flags are stored to EEPROM.
My problem is when i save ALL three numbers to EEPROM one by one, My Slave_2, which is been read previous from EEPROM and stored to SRAM is manipulated.
I dont know why it is happening and i just stuck.
here is code snaps which illustrates how flow goes.

Code:
Code:
int ReadEEPROM()
{
   char str[100];
   //number_1 flage
   NUMBER_FLAGE_1 = eeprom_read_byte(&EE_NUMBER_FLAGE_1);
   //number_2 flage
   NUMBER_FLAGE_2 = eeprom_read_byte(&EE_NUMBER_FLAGE_2);
   //number_3
   NUMBER_FLAGE_3 = eeprom_read_byte(&EE_NUMBER_FLAGE_3);
   //number_4
   NUMBER_FLAGE_4 = eeprom_read_byte(&EE_NUMBER_FLAGE_4);
   
   //retrive the Save flage information
   SLAVE_FLAGE_1 = eeprom_read_word(&EE_SLAVE_FLAGE_1);               //Slave_1 flage
   SLAVE_FLAGE_2 = eeprom_read_word(&EE_SLAVE_FLAGE_2);               //Slave_2 flage
   SLAVE_FLAGE_3 = eeprom_read_word(&EE_SLAVE_FLAGE_3);               //Slave_3 flage
   SLAVE_FLAGE_4 = eeprom_read_word(&EE_SLAVE_FLAGE_4);
   //COPY SLAVE FROM EEPROM
   //Slave_1
   eeprom_read_block((void*)&SLAVE_1, (const void*)&EE_SLAVE_1,7);   
   
   eeprom_read_block((void*)&SLAVE_2, (const void*)&EE_SLAVE_2,6);   //number_2

   eeprom_read_block((void*)&SLAVE_3, (const void*)&EE_SLAVE_3,6);   //number_3   

   eeprom_read_block((void*)&SLAVE_4, (const void*)&EE_SLAVE_4,6);   //number_3

   //retrive the number flage information
   
   
   
   eeprom_read_block((void*)&NUMBER_1, (const void*)&EE_NUMBER_1, 13);
   eeprom_read_block((void*)&NUMBER_2, (const void*)&EE_NUMBER_2,13);   //number_2
   eeprom_read_block((void*)&NUMBER_3, (const void*)&EE_NUMBER_3,13);   //number_3
   eeprom_read_block((void*)&NUMBER_4, (const void*)&EE_NUMBER_4,13);
}


here how i write data to EEPROM
Code:
Code:
void RegisterNumber(char *number)               //Register Number with master
{

   if(NUMBER_FLAGE_1==0){
      
      strcpy(NUMBER_1,number);

      NUMBER_FLAGE_1=1;
      
      eeprom_write_block ((void*)&NUMBER_1, (const void*)&EE_NUMBER_1,13);
      eeprom_write_byte(&EE_NUMBER_FLAGE_1,NUMBER_FLAGE_1);
}
   else if(NUMBER_FLAGE_2==0){
      
      strcpy(NUMBER_2,number);

      NUMBER_FLAGE_2=1;
      eeprom_write_block ((void*)&NUMBER_2, (const void*)&EE_NUMBER_2,13);
      eeprom_write_byte(&EE_NUMBER_FLAGE_2,NUMBER_FLAGE_2);

   }
   else if(NUMBER_FLAGE_3==0){
      
      strcpy(NUMBER_3,number);

      NUMBER_FLAGE_3=1;
      eeprom_write_block ((void*)&NUMBER_3, (const void*)&EE_NUMBER_3,13);
      eeprom_write_byte(&EE_NUMBER_FLAGE_3,NUMBER_FLAGE_3);
   }
   else if(NUMBER_FLAGE_4==0){
      
      
      strcpy(NUMBER_3,number);

      NUMBER_FLAGE_4=1;
      eeprom_write_block ((void*)&NUMBER_4, (const void*)&EE_NUMBER_4,6);
      eeprom_write_byte(&EE_NUMBER_FLAGE_4,NUMBER_FLAGE_4);
   }
}


i read EEPROM at the starting of initializing the code and store to SRAM.I hope I am making my self clear.
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…