This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to print float values using SEGGER RTT

Hi, My question is similar to this devzone.nordicsemi.com/.../ but I can't get it to work.

I am using SEGGER_RTT_WriteString and sprintf for debugging, but I am not able to print a float value such as 3.1415. I use the folowing code for printing intergers and it works fine:

uint8_t int_value;

int_value = 129;

char int_str[80];

sprintf(int_str, "Integer value is %d\n", int_value);

SEGGER_RTT_WriteString(0, int_str);

I am then trying to print a float value in the same way, but I have had no success so far. I have tried with "%f", "%0.2f"etc, but the printing result is just nothing or 0.

float float_value;

float_value = 3.1415;

char float_str[80];

sprintf(float_str, "Float value is %f\n", float_value);

SEGGER_RTT_WriteString(0, float_str);

Any suggestions are very much appreciated. Thanks!

Parents
  • I am using the stdio library. When I look in the stdio.h file I can find the following description:

    "Some library variants do not support the \q{f} and \q{F} conversion specifiers in order to reduce code and data space requirements; please ensure that you have selected the correct library in the \b{Printf Floating Point Support} property of the project if you use these conversion specifiers."

    It is not described specifcally under the fprintf or printf declaration though.

    If I go to the Project Options under Printf/Scanf under the Linker section, then there is an option to set 'Printf Floating Point Supported' to either Yes or No. It is by default set to No.

    After setting this option to Yes it works:-)

    Thank you so much for your help!

Reply
  • I am using the stdio library. When I look in the stdio.h file I can find the following description:

    "Some library variants do not support the \q{f} and \q{F} conversion specifiers in order to reduce code and data space requirements; please ensure that you have selected the correct library in the \b{Printf Floating Point Support} property of the project if you use these conversion specifiers."

    It is not described specifcally under the fprintf or printf declaration though.

    If I go to the Project Options under Printf/Scanf under the Linker section, then there is an option to set 'Printf Floating Point Supported' to either Yes or No. It is by default set to No.

    After setting this option to Yes it works:-)

    Thank you so much for your help!

Children
No Data
Related