cancel
Showing results for 
Search instead for 
Did you mean: 

how can I save 2 bytes in eeprom using c

apytel1
Associate II
Posted on July 18, 2007 at 15:47

how can I save 2 bytes in eeprom using c

16 REPLIES 16
sisto
Associate II
Posted on December 28, 2006 at 15:57

Hi apyTel1,

You must declare eeprom space into .lkf file :

+seg .eeprom -b 0x1000 -m 0x7f

Then in a Your source file You must declare :

 

#pragma space[] @eeprom @near

 

 

@near unsigned int var1;

 

@near unsigned int var2;

 

 

// etc, etc

 

 

#pragma space[] @tiny

 

// To write eeprom registers (example)

writeE2Rom(&var1,eValue);

// To Read eeprom registers (example)

 

@tiny unsigned int eeromValue;

 

 

eeromValue = ((var1<

 

// Prototypes

void writeE2Rom(@near unsigned int *address, unsigned int value)

{

setWriteMode; // E2LAT = 1; E2PGM = 0

*address = MSB(value); // High Byte of value

*address+1 = LSB(value); // Low Byte of value

startProg; // E2Lat = 1; E2PGM = 1

SetBit(EEROM_Status,_eeWaitFlag); // Wait until program is completed (1)

}

/*

Notes

1) before a write cycle, You must check the end of previous programming operation by polling E2LAT flag until equal 0.

ST7Lite0x Data Sheet reference 17/125 and 18/125

Sixtus

apytel1
Associate II
Posted on December 28, 2006 at 16:47

Thank you very much.

Tomorow i try again.

best regards

andrzej

gavin1
Associate II
Posted on July 17, 2007 at 14:28

Apologees but I'd like to finish up a few things on this thread.

I'm trying to use the Cosmic compiler to read and write to EEPROM on a ST7FLITE39.

I'm using ST7VD to develop my code.

I have added eeprom.s and eeprom.i to my project.

I declare my variables as

e.g. @near @eeprom unsigned char myVar = 0;

Then I disable automatic linker file generation in Project Settings > Linker > Input.

Then I add line to my linker file

+seg .eeprom -b 0x1000 -m 0x20

And in my code I set myVar:

myVar = 1;

When I attempt to load this in ST7VP I receive :

Address 0x1000 is out of range and is ignored!

If I ignore this and program I can program the Program memory. On running the application I expect to see 0x01 in Data Memory location 0x1000 when I read the Data Memory tab from the IC using ST7VP.

This is not the case.

My remaining questions are:

Should I receive the address out of range error?

Are there any further modifications required for the eeprom code to work?

gavin1
Associate II
Posted on July 18, 2007 at 06:36

Following another post from ''mjg21cncn'' I notice that I can continue to allow STVD7 to generate auto link file by going to following:

Project Settings->Linker->Input

Expand Item ''Zero Page''

Add entry .eeprom

If I do this then I notice that I am able to read back my initial entry from the eeprom.

gavin1
Associate II
Posted on July 18, 2007 at 07:02

OK on further inspection it appears I am wrong. 8 chars all value 0x00 appear to get written to my EEPROM regardless of what the values are set to in the application.

luca239955_st
Associate III
Posted on July 18, 2007 at 08:02

please post your linker file and the listing file (the .la is better than the .ls, look in the manual to see how to produce it) so that we can take a look.

Regards,

Luca (Cosmic)

PS: I'll be on holiday soon and I'm not sure I'll be able to follow this thread. If you don't get useful support here please contact

mailto:support@cosmic.fr

.

gavin1
Associate II
Posted on July 18, 2007 at 15:47

I received some great advice from our ST7 supplier which allowed me to build and run the application successfully.

I copied eeprom.s and eeprom.i to my project directory, then changed the line in eeprom.i to point to the address of the EEPROM in the datasheet (Listed as EECSR in the ST7FLITE39 hardware register map)

EEPCR: equ $30 ; control register

I also added a function in my C code to reset the watchdog timer

void reset_watchdog(void)

{

WDGCR = 255;

}

and added a function declaration to my eeprom.s

xref _reset_watchdog

which I call from within the wait loop of c_eewrc

Finally I edited the line in the linker file associated with the .eeprom space:

+seg .eeprom -b 0x1000 -m 0x100 -n .eeprom -c

Adding the ''-c'' at the end.

Now ST7VP does not complain about the out of range (eeprom) variables. And my application can read and write from the EEPROM on the IC.

:D