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.

CC2640R2F-Q1: Trying to print Float values using Log_info1

Part Number: CC2640R2F-Q1

Hello,

I'm trying to print some float values on my project. My application is based on Project Zero example that uses Log_Info to print via UART. I already searched for related questions on this forum and added this line to app_ble.cfg as stated by some people that it worked for them: 

System.extendedFormats = "%f";

But that didn't work as all I get when I try to print my value is "0.0000" for a value that should be between 0.25 and 0.5.

This is the line that prints the float value:

Log_info1("roll = %f", roll);

And roll was declared as a float type.

I know that is unadvised to use floats but this time is a must.

Best regards and thanks.

  • Miguel,

    Have you debugged and watched the variable to ensure it has the correct value when you are logging it?

    Also, from the XDC documentation:

    Did you make sure to include 

    var System = xdc.useModule('xdc.runtime.System');

    in your .cfg file? 

    Have you tried using the floatToArg() macro?

    Regards,

    Daniel

  • I test this with project_zero in latest simplelink_cc2640r2_sdk_4_30_00_08 and I also see "0.0000" which is the same problem as Miguel's. It seems Log_info1 doesn't process float format.

  • , I try to use "Log_info1("roll = %f", (float)0.1);" to print float but as you can see it shows "roll = %f" in fmt of UartLog_log. This definitely shows UartLog doesn't handle float well.

  • Hello Daniel,

    Yes, I did make sure to add this line into .cfg file

    var System = xdc.useModule('xdc.runtime.System');

    But it still showed "0.0000". The same with floatToArg() macro.

    As said by Yikai Chen, when these lines are added the Log_info1 instructions shows "0.0000" instead of the float value it is suposed to show (verified in debug that variable holds right value but shows 0.0000 in print). That would suggest that the problem is related to how the Log_info1 handles float values. I have other applications implemented that are based on MultiRole example that uses Display_print instead of Log_info to print to UART, I test to see if Display_print can print floats properly but I would like not having to change from Log_info to Display_print in Project Zero based app.

    Looking forward for your comments, 

    Regards,

  • Miguel,

    I looked into this, and the issue is that UartLog.c isn't able to handle floats. UartLog.c is the UART-based implementation of the Log module. I think your best bet is either to format the float into two ints (one for whole number, one for decimal) or sprintf the float into a string and pass that to Log_info.

    Regards,

    Daniel

  • Hello Daniel,

    The second option looked easier to me and that was the path that I followed. I managed to implement this piece of code to succesfully print the float values needed

            sprintf(strRoll, "%.3f", roll);
            Log_info1("Roll = %s", (IArg)strRoll);

    And strRoll was declared as:

    char strRoll[20];

    So it could properly hold the string. Note that stdio.h and stdlib.h need to be added to the code for it to compile.

    Thanks for the guidance.

    Regards.