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?" Hints: 1. union 2. pointer
I'd add this to the hint list: 3. sizeof
unsigned char *ptr; ptr = (unsigned char *ptr)&MyUserRecStruct; ...
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 */