Gday,
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
sendser(BYTE_H(frac16Val));
sendser(BYTE_L(frac16Val));
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,
Laurence
Hi again,
I would just like to post a follow up to this.
I was messing around and created 2 programs that sent static info from the DSC to my PC.
All it does is send -1 to 1 in increments of 0.1 to the PC, which attempts to reinterpret
This is the output:
[ -1.000000 ]
[ -0.001556 ]
[ -0.003113 ]
[ -0.699982 ]
[ -0.599976 ]
[ -0.500000 ]
[ -0.001556 ]
[ -0.003113 ]
[ -0.199982 ]
[ -0.099976 ]
[ 0.000000 ]
[ -0.001587 ]
[ -0.003143 ]
[ 0.299988 ]
[ 0.399994 ]
[ 0.500000 ]
[ -0.001587 ]
[ -0.003143 ]
[ 0.799988 ]
[ 0.899994 ]
[ -0.000031 ]
I can see that it is correctly converting some of the values, IE -1, -.7, -.6, -,5 etc, but you can see it just screws up on some of the values!
Any ideas?
Hi,
You must take into account the endianess of two different micros:
on PC is little endian, so you must send in order sender(BYTE_LSB), sender(BYTE_MSB).
Or take into account that on PC side and re-assemble correctly the word.
Regards,
IPA
Hi there Ipa,
Well, I must apologise! I figured this little tidbit out the morning after I posted my last message. So, I'm happy to say, I have it all working. I just neglected to post about it!
Thanks again,
Laurence