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.

CCSTUDIO-C2000: pintf() issue-how to print single precision floating in eabi

Part Number: CCSTUDIO-C2000

hi, experts 

    may you have a nice day!

    In eabi, printf() is double64, how to print single precision floating point variables.

      CCS 11.2.0

      compiler v22.6.0   and v21.6.0

      device:   280025C

     C2000ware : V4.01

   

 

  • Hi Matt,

    Sadly SCIprintf() and likely C++ printf() functions do not directly support floating point placements. A basic work around is to fake the printout by adding (0.) to the text part of the command syntax. On the other hand, CCS debug will show variables with floating point decimals for the same one being printed without decimal points.

    Regards,

  • I decide to pintf the Hexadecimal format instead.

    thank you very much! may you have a nice day!!

  • I decide to pintf the Hexadecimal format instead.

    Seemingly TI needs to update C language library to do floating point prints in these older library functions. Their trend has been to give them a knockout punch deprecate them. 

  • Thanks for your reminder, I have implemented the print function.

    TI's library does not support this function very well. It needs to be manually modified to increase the space of stack(0x600 for 280025) and heap(0x400 for 280025) and adjust the cmd file(put .cio into bigger RAM).

  • Nice find Matt Grinning. For awhile now I have been using the SCIprintf() but that is via XDC110 VCOM3. 

  • In eabi, printf() is double64, how to print single precision floating point variables.

    When a float value is passed to printf, the compiler automatically converts it to double before passing it.  Other than that, printf of a float value is no different than printf of any other value.

    Thanks and regards,

    -George

  • Other than that, printf of a float value is no different than printf of any other value.

    What about printing the decimal point? I believe that is what Matt was referring to. I mention SCIptrintf() has the same issue to properly print any CHAR (%c) besides the floating decimal point values print out as gibberish numbers anyway.

  • What about printing the decimal point?

    That depends on the format (%f, %e, %g, possibly with precision) you use.  It works the same whether a float or double value is passed.

    I mention SCIptrintf()

    I am not familiar with SCIprintf.  My comments are relevant only to printf.

    Thanks and regards,

    -George

  • Same problem with Tivaware UARTPrintf() no decimal point prints as a matter of double precision. SCIprint() is from C2000 driver lib utils folder. 

    This has become more topic of the day in many MCU forums that output floating point values. The only way to get serial data floating widgets is to move the decimal by variable division, something left over from 1990's.

    The %x.1f needs to be placed in the call to printf a decimal point but it's not floating point precision from what I gather here.

    The printf conversion specification %3.Of says that a floating-point number (here fahr) is to be printed at least three characters wide, with no
    decimal point and no fraction digits. %6 • 1f describes another number (celsius) that is to be printed at least six characters wide, with 1digit after
    the decimal point. The output looks like this:

    o  -17.8
    20  -6.7
    40  4.4

    Width and precision may be omitted from a specification:

    %6f says that the number is to be at least six characters wide; %. 2f specifies two characters after the decimal point, but the width is not constrained; and %f merely says to print the number as floating point. "d print as decimal integer ""6fd print as decimal integer, at least 6 characters wide print as floating point "6f print as floating point, at least 6 characters wide ".2f print as floating point, 2 characters after decimal point "6.2f print as floating point, at least 6 wide and 2 after decimal point Among others, printf also recognizes %0 for octal, %x for hexadecimal, %c for character, %8 for character string, and %% for" itself.