Pragma variable in EEPROM

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Eugenio966
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hello,

 

I would like to store permanently 2 variables in the EEPROM.

Currently we have just 1 variable as shown below:

#pragma abs_address 0x1f00 // Start address of block 62 (This device has 64 blocks of 128 bytes)
const int check_variable = 0; // The initial value of the variable
#pragma end_abs_address

...................

volatile char lvd_occurred = FALSE;
#pragma interrupt_handler lvd_handler;

void lvd_handler (void )
{
lvd_occurred = TRUE;
}

void main(void)
{

.............................................

value_for_variable = constant;
if (lvd_occurred != TRUE)
{

bError = E2PROMx128_1_bE2Write(0, (unsigned char *)&value_for_variable, 2, 25);
}

 

The "constant" value is stored permanently in the EEPROM.

How can we declare and assign a second one?

Many thanks

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Eugenio,

The simplest way that I usually declare multiple variables in EEPROM is to declare a structure (struct) of the data.

Here's an example:

typedef struct
{
  uint8 data1;   // first data
  uint16 data2;  // second data
  uint32 data3;  // third data.
// Add more data if needed.
}  ee_data_struct;

// declare the variable in RAM
ee_data_struct ee_data =
{  // Set the default data settings
.data1 = 0x55;
.data2 = 0xFEDC;
.data3 = 0x01234567;
}

/********************************/
void store_EE_data(void)
{
...
// This will write the entire ee_data structure.
   bError = E2PROMx128_1_bE2Write(0, (unsigned char *)&ee_data,sizeof(ee_data), 25);
...
}

/********************************/
void main(void)
{
...
// Change ee_data vars.
   ee_data.data1 = 0xAA;
...
   ee_data.data2 = 0xEDCB;
...
   ee_data.data3 = 0x98765432;
...
// Store the ee_data changes in E2PROM.
   store_EE_Data();
}
Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
3 Replies
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello @Eugenio966 

From your description of the issue, I guess you are using an external EEPROM and have interfaced it
with PSoC. Can you please provide more details of the device you are using? Which PSoC device are you using?

How are you communicating with it?

Also provide more information regarding your application (and attach your project if possible) so that we can help with this.

Best Regards
Ekta

0 Likes
Eugenio966
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hi Ekta,

We are not using any external EEPROM.

it is IC internal EEPROM. We are using CY8C20xx7 devices.

Eugenio

 

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Eugenio,

The simplest way that I usually declare multiple variables in EEPROM is to declare a structure (struct) of the data.

Here's an example:

typedef struct
{
  uint8 data1;   // first data
  uint16 data2;  // second data
  uint32 data3;  // third data.
// Add more data if needed.
}  ee_data_struct;

// declare the variable in RAM
ee_data_struct ee_data =
{  // Set the default data settings
.data1 = 0x55;
.data2 = 0xFEDC;
.data3 = 0x01234567;
}

/********************************/
void store_EE_data(void)
{
...
// This will write the entire ee_data structure.
   bError = E2PROMx128_1_bE2Write(0, (unsigned char *)&ee_data,sizeof(ee_data), 25);
...
}

/********************************/
void main(void)
{
...
// Change ee_data vars.
   ee_data.data1 = 0xAA;
...
   ee_data.data2 = 0xEDCB;
...
   ee_data.data3 = 0x98765432;
...
// Store the ee_data changes in E2PROM.
   store_EE_Data();
}
Len
"Engineering is an Art. The Art of Compromise."
0 Likes