2022-11-22 05:43 PM
Hello,
I am a newbie in struct.
I have a struct declaration below.
typedef struct __serial_data
{
uint8_t frameStart;
uint32_t data;
} serial_data;
serial_data mydata[25];
but frameStart is allocated 32bit in memory and this causes trouble when sending through UART.
Initialize the struct.
for(uint16_t cntr = 0; cntr < 25; cntr++)
{
mydata[cntr].frameStart = 0xAA;
mydata[cntr].data = cntr + 1;
}
Memory watch
Send to UART
Memory location
Is there any way to send data like:
AA, 01, 00, 00, 00,
AA, 02, 00, 00, 00,
AA, 03, 00, 00, 00,
AA, 04, 00, 00, 00,
......
Where:
AA = frame start (8bits)
01 = data (32bits)
Or the only way to do it is to make a separate array and arrange it accordingly and manually?
Solved! Go to Solution.
2022-11-22 07:26 PM
32 bit data are typically 4 byte modulo address, so is the beginning of a variable. Start by declaring a 5 byte array and fill it up manually. Otherwise, your code will be affected from little or big endianess that might bite you back in the future....
2022-11-22 06:08 PM
2022-11-22 07:26 PM
32 bit data are typically 4 byte modulo address, so is the beginning of a variable. Start by declaring a 5 byte array and fill it up manually. Otherwise, your code will be affected from little or big endianess that might bite you back in the future....