We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I did read some threads on the forum but could not solve my problem.
I want to make a union of to data sets (a structure and an array).
My code is as follows:
#define COMMS_BUFFER_SIZE 80 #define PROTOCOL_HEADER_SIZE 5 #define PROTOCOL_DATA_SIZE (COMMS_BUFFER_SIZE - PROTOCOL_HEADER_SIZE)
typedef struct { u8 StartByte; u8 Route; u8 Command; u8 Length; u8 HCS; u8 Data[PROTOCOL_DATA_SIZE]; }TProtocol;
typedef union { TProtocol Protocol; u8 Data[COMMS_BUFFER_SIZE]; }TCommsBuffer;
extern TCommsBuffer CommsBuffer;
I want to access the contents of "TCommsBuffer" in the protocol format (strucrure) or as a array.
CommsBuffer.Data[x] = x; CommsBuffer.Protocol.StartByte = x;
But it gives me problems.
When I read data into the Protocol structure, it repeats the contents of the 1st 5 bytes of the protocol structure into its data section.
Is this the correct way to define the union?
I gather that what you want to do is to have a structure 'loaded' via the UART.
now risking the ire of the smoked sardine, here is a dirty trick I use for that particular purpose:
in structs.h typeded struct { .... } STR_RSIF in defines .h // duplicate names extern xdata STR_RSIF GSTrsin; extern UX8 GSTrstp[]; in a .a51 module ..... PUBLIC GSTrstp PUBLIC GSTrsin ...... GSTrstp: ds 0 ; duplicate of the below GSTrsin: ds 0100h ; what it is (withheld)
totally nonstandard, totally not portable, uses assembler and I am sure Mr. Sprat can find more to pour bile about, but it works and does not in any way violate the specification of the tools (Keil).
Erik
No, no, I don't have a problem reading data from the UART I have a problem with incorrect data afters its been captured by the UART.
Solved the problem
And how will you help others with their similar problems, unless you spend an equal amount of time describing what the problem was, and how you solved it?
Sorry, but I feel bad, it was finger trouble!!
LATE NIGHTS = FINGER TROUBLE (MISTAKES)
I thought that I was reading the contents of "RXBuffer.Protocol.Data" but I was actually reading "RXBuffer.Data"