I am working with a F28335 from TI communicating serially (RS-232) with a PC.
In matlab, i need to calculate some double numbers and send them serially to the controller.
For that, for example, i have 1.00e-5, and i convert it to individual bytes using:
Time1On = typecast(Time1On, 'uint8');
The result is:
172 197 39 55
Then I convert this to hex, and i manage to turn it into a string to send it
ACC52737
I send this serially to the F28335, and i get the correct value into a Uint32 variable (a position in an array), but i can't seem to find a way to copy this same individual bytes into a double value, that would get me the same original fraction number.
I tried casting from a Uint32 array, where the received value is correctly stored:
dataDouble = (double) (*(RxPacket.RcvData + RxPacket.idxData));
But I get this:
11100000000000000000000000000000 or 2.898602e+09
And I tried storing it as a union:
union doubleConstruct{
double Val;
Uint16 rxArray[2];
};
and saving the 16 word separately (i encode every 16 bits with hamming parity, and decode the 16bits words) into the positions of the array, but the double result is the same...
Anyone has ever broken doubles into bytes and sent them serially? If yes, how did you later composed and recovered the respective double number? Is there a way to just stampo bits of an unsigned int into a double?
Thx!
float? - Some programmer dudedoubletype takes 64bits and not 32. You might need to usefloat. Why do you convert to hex string? sending four bytes is not enough? - Shaifloatvariable (Val) using theunionI declared. I get exactly the bits (ACC52737) I want in it, but the C program interprets this float as-5.60343e-12while I'm supposed to be getting1.00e-5. Different interpretations of the same float number??? - user2991509typecast()function in matlab gives you the individual bytes of thesinglerepresentation, but you get the LSB in position 1, and the MSB in position 4... WHYY MATLAB WHYY?? If you don't want to deal with typecast you can also usenum2hex()which will give the hex value of thesinglerepresentation in the right order. - user2991509