Skip to main content
Visitor II
July 18, 2007
Question

how can I save 2 bytes in eeprom using c

  • July 18, 2007
  • 16 replies
  • 3434 views
Posted on July 18, 2007 at 15:47

how can I save 2 bytes in eeprom using c

    This topic has been closed for replies.

    16 replies

    apytel1Author
    Visitor II
    November 16, 2006
    Posted on November 16, 2006 at 08:12

    Hello

    I use st7flite09 and stvd3 and cosmic c.

    I want to store two bytes in eeprom.

    How can I do it?

    I wrote in main.c:

    @eeprom char var1;

    @eeprom char var2;

    and I became error:

    #error clnk Debug\sw-dimm.lkf:1 no default placement for segment .eeprom

    How can I fix it?

    Please help me.

    Visitor II
    November 16, 2006
    Posted on November 16, 2006 at 12:52

    you must tell the linker where it must put the linker file. This is done by adding a line like

    +seg .eeprom -b0x0C00 -c

    in your .lkf

    Regards,

    Luca (Cosmic)

    apytel1Author
    Visitor II
    November 17, 2006
    Posted on November 17, 2006 at 05:09

    Thanks Luca

    I try it and no luck. I write 0x1000 (first byte in eeprom) no luck.

    I have question: how can I modify *.lkf file? It is done by linker.

    This is my first step in st7 and c language ( befor I write only assemler for family '51)and I can't find solution for this problem.

    I must write something in main.c and then linker modify *.lkf?

    Visitor II
    November 20, 2006
    Posted on November 20, 2006 at 12:24

    the linker file is read by the linker. It is a plain text file that you can modify with any editor. If you use STVD7, the linker file is generated automatically: either you use STVD7 menu until the linker file looks like you want, or you choose the option to edit it by habd.

    Whatever way, once you have a line in your linker file like I explained in my first anwer, you are ready to go.

    Regards,

    Luca

    apytel1Author
    Visitor II
    November 22, 2006
    Posted on November 22, 2006 at 04:58

    it's immposible!

    I wrote extra line like you said me: +seg .eeprom _b 0x1000 -c in *.lkf file.But when I try to start ''build'' function in STVD7 *.lkf file is automaticaly overwrite and my line is deleted.

    I write my program in STVD 7 , maybe I must change anything in options (but I don't know where).

    Visitor II
    November 24, 2006
    Posted on November 24, 2006 at 12:06

    In Project->Settings->Linker->Input, untick the 'auto' box beside the 'Script Lkf file name' text box.

    You will then need to re-write the linker file with the extra segment locator (i.e. go back and add +seg .eeprom _b 0x1000 -c).

    Visitor II
    December 7, 2006
    Posted on December 07, 2006 at 11:09

    I believe I might have similar problems to above. My application only works when I don't use certain I/O ports. Is there any documentation for editing the linker file. Can't find any in the IDEA help... I assume that the linker documentation is what I'm seeking.

    Visitor II
    December 7, 2006
    Posted on December 07, 2006 at 11:18

    The linker doesn't know about I/O ports, only memory addresses. What is the error you are having?

    Visitor II
    December 7, 2006
    Posted on December 07, 2006 at 13:44

    the linker documentation is actually a chapter of the compiler manual. This manual is installed with every compiler, or you can find it

    http://www.cosmic-software.com/downloads/docs/cxst7.zip

    Regards,

    Luca (Cosmic)

    Visitor II
    December 28, 2006
    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