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.

CCS/EK-LM4F120XL: Problems printing floats to the UART!

Part Number: EK-LM4F120XL

Tool/software: Code Composer Studio

Hello, 

I have been developing a signal acquiring program, one that calculates RMS values, frequencies and such. It has been working just fine, but I'm having trouble while trying to print the float values to the UART, as seen in the image. I have configured the UART the right way, because the UART does print int numbers. I've read on the forums and on the TI wiki about --printf_support and I have also set it to full, but I dont know if that helps or not when talking about UART prints. Could someone help please?

Regards, Tales Duque.

  • Hello Tales,

    Our Sensor Hub examples have a few ways to convert floats for UART printing. I'll post one of them:

            //
            // Get a local copy of the latest data in float format.
            //
            TMP006DataTemperatureGetFloat(&g_sTMP006Inst, &fAmbient, &fObject);
    
            //
            // Convert the floating point ambient temperature  to an integer part
            // and fraction part for easy printing.
            //
            i32IntegerPart = (int32_t)fAmbient;
            i32FractionPart = (int32_t)(fAmbient * 1000.0f);
            i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
            if(i32FractionPart < 0)
            {
                i32FractionPart *= -1;
            }
            UARTprintf("Ambient %3d.%03d\t", i32IntegerPart, i32FractionPart);
    
            //
            // Convert the floating point ambient temperature  to an integer part
            // and fraction part for easy printing.
            //
            i32IntegerPart = (int32_t)fObject;
            i32FractionPart = (int32_t)(fObject * 1000.0f);
            i32FractionPart = i32FractionPart - (i32IntegerPart * 1000);
            if(i32FractionPart < 0)
            {
                i32FractionPart *= -1;
            }
            UARTprintf("Object %3d.%03d\n", i32IntegerPart, i32FractionPart);

    This thread also has some advice on printing floats: https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/313525/1090648#1090648

  • I see what you did there, very interesting! Thanks for replying, helped me a bunch!

    Tales.