Skip to main content
Visitor II
April 5, 2025
Question

EEPROM Emulation: meaning of the VirtAddVarTab

  • April 5, 2025
  • 1 reply
  • 308 views

I am really confused about the meaning of the VirtAddVarTab that is filled with number from 1 to NB_OF_VAR.

My understanding is that is used to copy from one page to the other when the first is full.

Anyway I had to save a structure to EEPROM and reload it from but I am no shure that what i'm doing is correct, even if it is working. My concern is that I'm not using this VirtAddVarTab to refer to the (virtual) eeprom locations.

This is my code 

void WRITE_STRUCT_EEPROM(eeStorage_t eep) {



uint8_t LEE[sizeof(eep)];

uint8_t a, i;



// MyData = sizeof(eep);

a = 1;

// dest source nofb

memcpy(&LEE, &eep, sizeof(eep));

for (i = 0; i < sizeof(eep); i += 2) {

res = EE_WriteVariable(a, LEE[i] | (LEE[i + 1] << 8));

a++;

}

}



eeStorage_t READ_STRUCT_EEPROM(void) {

eeStorage_t eep;

uint16_t bdata[2];

uint8_t LEE[sizeof(eep)];

uint8_t a, i;



a = 0;

for (i = 1; i < sizeof(eep)/2+1; i++) {

res = EE_ReadVariable(i, &bdata[0]);

// res = EE_ReadVariable(i + 1, &bdata[1]);

LEE[a] = (uint8_t) bdata[0];

a++;

LEE[a] = (uint8_t) (bdata[0] >> 8);

a++;

}

memcpy(&eep, &LEE, sizeof(eep));

return eep;

}

 

    This topic has been closed for replies.

    1 reply

    Graduate II
    April 5, 2025

    VirtAddVarTab is only demo example helper array. Isnt required. And demo code is simply disaster.