2024-01-02 06:38 AM
I am casting a Byte array (results from ADC) to a long, but occasionally - about 1:100000, it get the sums wrong. I've got to the line in the code where it goes wrong, and it is when it is casting a byte array to a long (I use union Method).
//Signed ADC Value - so 24-bit value can be shifted in
union
{
uint8_t b[4];
int32_t l;
}I32ADCValue;
//Populate the Raw mV Array
for(i=0;i<8;i++)//Loop for each channel
{
I32ADCValue.b[3]=ads1298rData.ADCMsg.Channel[i][0];
I32ADCValue.b[2]=ads1298rData.ADCMsg.Channel[i][1];
I32ADCValue.b[1]=ads1298rData.ADCMsg.Channel[i][2];
I32ADCValue.b[0]=0;
//Channels are not in sequence - create temporary array here.
mVx[i]=(I32ADCValue.l*Gain_mV);
}
When I run the debugger, it is having too bit a blue in I32ADCValue.l - in fact where I set .b[0] to 0, it is not after it has cast it.....any clues?
Solved! Go to Solution.
2024-01-02 06:50 AM
Looks correct to me. 756497664 = 0x2D_17_3D_00. Those are the values in the array. Values are stored in little-endian format. Perhaps you are assuming big-endian, but then it would not be working ever, so it's unclear.
> it is having too bit a blue in I32ADCValue.l
Huh? Proofread a bit, please.
2024-01-02 06:50 AM
Looks correct to me. 756497664 = 0x2D_17_3D_00. Those are the values in the array. Values are stored in little-endian format. Perhaps you are assuming big-endian, but then it would not be working ever, so it's unclear.
> it is having too bit a blue in I32ADCValue.l
Huh? Proofread a bit, please.
2024-01-02 09:40 AM
Ah, I found this not actually the problem. I checked the Big-Little Endian, and I had made an incorrect assumtion.