Laurence McLean

Reconstructing Frac16 Values

Discussion created by Laurence McLean on Jun 11, 2011
Latest reply on Jun 22, 2011 by Laurence McLean



I'm a bit new to the Freescale embedded world. I have a 56F8037 Dev board that I have been playing around with for a while now. Well, I am trying to get some serial data out of my board. (I havent been using Freemaster as part of my messings about include a linux host that talks to the board). Anywho, I have serial all up and going, but my problem is during the breaking down of Frac16 values for transmission and reconstruction at the other end.

In essence, I simply want to push out some Frac16 variables over serial so I can view them on my linux host.


On the DSC side of things, I have two defines, they are:


#define BYTE_L(x) ((x) & (unsigned short)0xFF)

#define BYTE_H(x) ((x >> 8) & (unsigned short)0xFF)


I then deconstruct a frac16 and send it over serial using the above defines, IE




On the PC side of things, I load the recieved data into a buffer then attempt to reconstruct it. I think this is where the problems arise!


I have a function on the PC side that I put the values from the buffer through to reconstruct them in to floating point versions of the Frac16. In theory, the floats should then contain some value from -1 to 0.9999999


float build_float(char upper, char lower)
    float float_val;
    return float_val = ((float)((((char)upper) << 8) | (char)lower) / 32768);   


Ie Resultant_Float = build_float(ser_buffer[0], ser_buffer[1]);


But, I am not getting expected values back.


Could anyone please cast an eye over this and let me know if I am on the right track?


Thanks very much,