This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Define struct on external EEPROM

Hello all,
I'm facing a little understanding problem.
At my design I use the AT89C51RD2 micro and also two external memory devices – SRAM and parallel EEPROM.
At my code I have several structs that I want them to be at the external EEPROM. What I did (and I think it's not OK) is to define such a parameter in the global memory area and then copy him to the external EEPROM. I think it's not OK to do so because I waste global memory area on data that I don't want him to be there. Also, in this case I receive duplicate data.
As I understand I can't do something like "volatile DATA xdata stData _at_ 0x8000;"
Where DATA is a struct compose from many data types like char, int and other structs.
Can anyone know a way to define a struct (bigger then one byte) directly in external memory?

Parents
  • There are a few things that I'm assuming here:

    1. Your EEPROM is located at 0x8000 in XDATA space.

    2. You have a struct (in EEPROM) that you want to read from and write to.

    If that's the case, you can just declare the struct as:

    volatile xdata struct bob _at_ 0x8000;

    And, the first structure member of bob will be at address 0x8000 in XDATA.

    Of course, you'll probably need some special way to write to bob since EEPROM writes are "typically" slower than writes to SRAM and wait states must be inserted manually.

    Jon

Reply
  • There are a few things that I'm assuming here:

    1. Your EEPROM is located at 0x8000 in XDATA space.

    2. You have a struct (in EEPROM) that you want to read from and write to.

    If that's the case, you can just declare the struct as:

    volatile xdata struct bob _at_ 0x8000;

    And, the first structure member of bob will be at address 0x8000 in XDATA.

    Of course, you'll probably need some special way to write to bob since EEPROM writes are "typically" slower than writes to SRAM and wait states must be inserted manually.

    Jon

Children
  • Thanks a lot Jon for your help.
    As I know your advice is OK in case where the size of struct members is byte, but what if one of them is array or string.
    Lets say the first struct member of bob is "char str[7];" and I want the struct to be initialized with "XYZ123". I can't use the strcpy function because external EEPROM needs NOPs between each byte write. So I need to declare the string in RAM and then copy it with special function to external EEPROM. The problem is that now I have this string in RAM and also in EEPROM.
    In this way RAM area is corrupt with unuseful data.
    Can you help in this case?

    Thanks a lot,
    Roberto