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.

Float over SCI with F28335

Hi,

I am currently trying to send a 32-bit floating point number over the SCI interface. Unfortunately every type conversion from float to unsigned int, that I tried, didn't work. My plan was to

- Convert float to uint
- Mask byte
- Bitshift
- Send byte over SCI

With

float test_float = 42.0;
Uint32   test_int

I tried both

test_int = (Uint32)test_float;

test_int = test_float;


but test_int was zero in both cases.

What is the proper way to do it ?

Thank you in advance.

~Brian

  • Hi Brian,

    I'd implemented something like this this:

    //Transmit Section
    actual_float = 45.33;
    gain = 5.44;
    float_gain = 45.33/5.44;

    int_value = float_gain;
    TXBUF=int_value;

    //Receive Section
    recv_value = RXBUF;
    actual_float = recv_value*5.44;

    Check this out and let us know. You'll have slight deviation for sure but you need to tweak the gain such that you can be closest to the actual value.

    Regards,
    Gautam

  • Hi Gautam,

    my issue is the preparation of the float value for the SCITXBUF. To perform the bitshift operation (8 databits), I guess I need to cast/convert the float to integer.
    In a few words: How to transmit a 32-bit float value via SCI ?
    Thank you !
    ~Brian
  • Brian Walsh said:
    my issue is the preparation of the float value for the SCITXBUF. To perform the bitshift operation (8 databits), I guess I need to cast/convert the float to integer.

    Yeah... That's a huge value.But you don't have to send this big value. Can you tell me what would be your highest float value? Be practical :)

    What about converting float to string? That would a painful and memory consuming job.

  • The value does not have to be huge. It's between +-10.0, but even if it was bigger, I could scale it down before transmitting, but I don't see a solution there. What do you mean ?

    If there's no easy solution, I would convert the float to IQ, transmit and 'decode' it on the PC.

    But it can't be so difficult !? The controller 'just' has to treat the 32-bit (float-)value as a kind of bit vector...

    ~Brian
  • I could solve it with a pointer:

    float my_float = 42.0;
    int *ptr;
    
    ptr = &my_float;
    
    SciaRegs.SCITXBUF = *(ptr+1) >> 8;
    SciaRegs.SCITXBUF = *(ptr+1);
    SciaRegs.SCITXBUF = *(ptr) >> 8;
    SciaRegs.SCITXBUF = *(ptr);

    Maybe not a professional solution, but it works for me.

    ~Brian

  • Until You're happy with the valid result :)

    Goodluck & Regards,
    Gautam