Answer the question
In order to leave comments, you need to log in
What is the correct way to work with UNION in C?
The ADUC814 controls the AD7793 ADC and communicates via RS232 to another AT89C51 MCU.
Previously, I operated only with 3 bytes, received them and transmitted them in this way:
union
{
unsigned long uD;
unsigned char uData[4];
} uDataUnion;
char i = 0;
uDataUnion.uData[0] = uDataUnion.uData[1] =
uDataUnion.uData[2] = uDataUnion.uData[3] = 0x00;
for (i = 1; i <= 3; ++i)
{
SPIDAT = 0x00;
while (!ISPI);
uDataUnion.uData[i] = SPIDAT; // запоминает принятый от AD7793 очередн. байт
ISPI = 0;
}
for (i = 3; i >= 0; --i)
{
Putc(kGainUnion.kGainArr[i]);
}
union
{
unsigned long int kGain;
unsigned char kGainArr[4];
} kGainUnion;
kGainUnion.kGain = ((2147483648 - pow(2, (31-gain))) + (uDataUnion.uD * pow(2, (7-gain))));
Answer the question
In order to leave comments, you need to log in
It is not entirely clear what you mean by "gluing" and what is the final task.
As I understand it, you read three bytes from the AD7793, save them. Then treat these three bytes as a 32-bit value (higher 8 bits are zeros), perform mathematical operations on them and send the result somewhere?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question