This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

The float value isn't correct in union

Other Parts Discussed in Thread: TMS320F28377S

Hi,

I used union is TMS320F28377S launchpad. But the float value isn't correct. 

union {
       float32 F_Data;
       Uint8 B_Date[4];
}Data1;

The HEX value of float 3.56 should be 0x4063d70a. I put these value into array. But the float value is not 3.56 (0x4063d70a). it change to 0x00d7000a. I appreciate if you tell me how to correct this issue. Thanks.

Regards,

John

  • John,

    The minimum data width on C28x is 16-bits. When you specify a char variable which might be 8-bits wide on some machines, it actually occupies 16-bits of memory on C28x. This is why the Hex value for each element of "B_Date" shows as 16-bits in the CCS expressions window and watch window.

    To represent 3.56f in the structure, you'll need only 2 elements:
    Data1.B_Date[0] = 0xD70A;
    Data1.B_Date[1] = 0x4063;

    Depending on what you're doing , there are compiler intrinsics to access byte data which may be helpful. Please see section 7.5.6 of the C28x Compiler User's Guide (spru514j): www.ti.com/.../spru514j.pdf

    Regards,

    Richard