I have a structure that is in my embedded Arduino code and the Windows PC program the communicates with it. When I use the structure in the PC code I have to add #pamaga pack (push,1) before the struct and #pragma pack(pop) at the end , so the data is aligned to one byte .
I have a bug in the Arduino code that is similar to what I had before adding Pop and Push to the Windows code.
Do I have to do something similar for the Arduino code. When I write to the Table array I get values in the wrong place when I read back.
Thank you Ray.
This is the structure.
#define STEPSTABLEX 14
#define STEPSTABLEY 2
// save the current data alignment setting to the stack
// and set data alignment to 1 byte
#pragma pack(push,1)
struct ECU_Cal {
uint8_t startChar; // $ Start character
uint8_t PacketHi;
uint8_t PacketLo;
uint8_t PacketID;
struct RealTimeData {
uint8_t startChar; // $ Start character
uint8_t PacketHi;
uint8_t PacketLo;
uint8_t PacketID;
uint16_t map;
uint16_t stepPos;
uint8_t stepStopSw;
uint16_t crcCnt;
} data;
struct SetupSettings {
uint8_t startChar; // $ Start character
uint8_t PacketHi;
uint8_t PacketLo;
uint8_t PacketID;
uint16_t table[STEPSTABLEY][STEPSTABLEX];
uint16_t crcCnt;
}setup;
uint16_t crcCnt;
};
//restore the previous data alignment
#pragma pack(pop)