EEPROM Problem

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
FGS
Posts: 2
Joined: Mon Jun 08, 2020 5:48 pm

EEPROM Problem

Post by FGS »

Hello !

I try to store different slots of datas in one page using the EEPROM library, my load and store functions are below this message.

It works when i have only the first slot edited, problems come when (in the order) : store first slot - store second slot - load first slot. Loaded datas seem to not make any sense. Additional question to this is : how can i save and store let's say 8 slots (2,5kBytes of datas). I guess i need two pages - and i m not sure how to adress the second page.

Thanks !

Code: Select all

void save_slot(int slot)     //1 SLOT TAKES 337 bytes
{

  int Status ;
  EEPROM.PageBase0 = 0x801F000;
  EEPROM.PageBase1 = 0x801F800;
  EEPROM.PageSize  = 0x800;
  
  int k = slot * 338 ;

  for (int i = 0 ; i < 16 ; i++)
    for (int j = 0 ; j < 7 ; j ++)
    {
      Status = EEPROM.write( k + ( 14 * i ) + ( 3 * j ), lowByte(mem[0][i][j] >> 8));
      Status = EEPROM.write( k + ( 14 * i ) + ( 3 * j ) + 1, lowByte(mem[0][i][j]));
      Status = EEPROM.write( k + ( 14 * i ) + ( 3 * j ) + 2, lowByte(mem[1][i][j]));
    }

  Status = EEPROM.write( k + 336, lowByte(current_mod));
  Status = EEPROM.write( 337, 1) ;     //REGISTER SAYING THE MEMORY HAS BEEN UPDATED WHEN THE DEVICE LIGHTS UP THE FIRST TIME
}

void load_slot (int slot)
{
  int Status ;
  int data ;

  EEPROM.PageBase0 = 0x801F000;
  EEPROM.PageBase1 = 0x801F800;
  EEPROM.PageSize  = 0x800;
  int k = slot * 338 ;
  
  for (int i = 0 ; i < 16 ; i++)
    for (int j = 0 ; j < 7 ; j ++)
    {
      mem[0][i][j] = 0 ;
      mem[1][i][j] = 0 ;

      data = EEPROM.read( k + ( 14 * i ) + ( 3 * j ));
      mem[0][i][j] = mem[0][i][j] | (data << 8) ;

      data = EEPROM.read( k +  ( 14 * i ) + ( 3 * j ) + 1);
      mem[0][i][j] = mem[0][i][j] | data ;

      data = EEPROM.read( k + ( 14 * i ) + ( 3 * j ) + 2);
      mem[1][i][j] = data ;
    }
  current_mod = 0 ;
  data = EEPROM.read(k +  336);
  current_mod = data ;

}

stas2z
Posts: 131
Joined: Mon Feb 24, 2020 8:17 pm
Answers: 8

Re: EEPROM Problem

Post by stas2z »

Looks like eeprom lib from libmaple core

FGS
Posts: 2
Joined: Mon Jun 08, 2020 5:48 pm

Re: EEPROM Problem

Post by FGS »

It is the one i found on Roger Clarke's Github as far as i remember :)

mrburnette
Posts: 275
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: EEPROM Problem

Post by mrburnette »

FGS wrote:
Tue Jun 09, 2020 1:14 am
It is the one i found on Roger Clarke's Github as far as i remember :)
The old forum can easily be searched via google:
https://www.google.com/search?q=eeprom+ ... oforum.com

Several posts deal with the proper syntax for using the faux-eeprom (flash) storage.
For example.

The official example is here.

Post Reply

Return to “General discussion”