loading struct from UART received data
Hi,
I am writing an embedded application which takes in messages from a UART and loads them into a struct. I want to add each incoming char into subsequent members in my interrupt routine. Here is the bones of the code I have so far
Code:
IncomingMessage.control_dollar = USART_ReceiveData(USART1);
if(char_counter == 0 && IncomingMessage.control_dollar != '$')
{
;
}
else
{
for(char_counter = 1; char_counter <= 16; char_counter++)
{
// writing remaining characters to struct
temp_data = USART_ReceiveData(USART1); // read data register to clear flag
}
}
char_counter = 0;
}
The USART_RecieveData is a device specific command which reads the data register and clears a flag, required after each char received.
My struct is:
Code:
typedef struct
{
vu8 control_dollar;
vu8 p;
vu8 s;
vu8 u;
vu16 address;
vu8 space;
vu16 controlString1;
} ControlMessage;
The issue I have is, how do I write to subsequent members within the for loop - if I put a member name in there it will just overwrite each time the loop goes round.
Regards
Dave