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

Read/write Structure variable byte for byte

Hello,

For our application I need to copy data from the XDATA RAM to a I2C EEPROM.
How can a structure variable (in XDATA) will be read byte for byte? Then I will copy it to the EEPROM. It would also be necessary to copy the data from the EEPROM into the structure variable.

My structure is defined like this:

typedef struct
	{	BYTE	XPIDNr[9];
		char	UserName[UserNameLength];
		BYTE	Test;
		BYTE	Test2;
		int	Count;
	}StructUserRec;

Could somebody give any hint?

Thanks in advance,

Machiel

Parents
  • Hello,

    you can use the union, as Andi told you:

    typedef union
    {
      BYTE    EepromByteArray[6];
    
      struct
      {
        BYTE  XPIDNr[9];
        char  UserName[UserNameLength];
        BYTE  Test;
        BYTE  Test2;
        int   Count;
      }
      StructUserRec;
    }
    EepromUnion_t;
    
    /* Declarations */
    
    EepromUnion_t    EepromUnion;
    
    
    /* Short names for struct/union members */
    
    #define EepromByte EepromUnion.EepromByteArray
    #define xpidnr     EepromUnion.StructUserRec.XPIDNr
    
    /* ... and so on */
    

    The short names are #defined for not to type in always the whole struct/union names.

    Jochen

Reply
  • Hello,

    you can use the union, as Andi told you:

    typedef union
    {
      BYTE    EepromByteArray[6];
    
      struct
      {
        BYTE  XPIDNr[9];
        char  UserName[UserNameLength];
        BYTE  Test;
        BYTE  Test2;
        int   Count;
      }
      StructUserRec;
    }
    EepromUnion_t;
    
    /* Declarations */
    
    EepromUnion_t    EepromUnion;
    
    
    /* Short names for struct/union members */
    
    #define EepromByte EepromUnion.EepromByteArray
    #define xpidnr     EepromUnion.StructUserRec.XPIDNr
    
    /* ... and so on */
    

    The short names are #defined for not to type in always the whole struct/union names.

    Jochen

Children
No data