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

How to print floats with NRF_LOG macros

Trying to print floats with NRF_LOG functions always prints a value of 0.00000.

E.g.

float value = 123.456; NRF_LOG_ERROR( "Float %f\r\n", value );

prints:

ERROR:Float 0.00000

but NRF_LOG_ERROR( "Float %u\r\n", (uint16_t)value );

prints

ERROR:Float 123

I have the _printf_float linker option enabled. It's clear from the output that something is recognizing the float param and handling it. How can I print floats to the LOG output?

Printing a char* string variable with "%s" also fails to compile.

Parents
  • There are special macros available for float values:

    NRF_LOG_ERROR( "Float " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(value));
    

    Note: These macros wrongly show values -1.0<value<0.0 as positive.

    Printing a char* string variable with "%s" also fails to compile.

    Try using nrf_log_push(). The -Werror gcc option may be incompatible with NRF_LOG_ functions.

Reply
  • There are special macros available for float values:

    NRF_LOG_ERROR( "Float " NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(value));
    

    Note: These macros wrongly show values -1.0<value<0.0 as positive.

    Printing a char* string variable with "%s" also fails to compile.

    Try using nrf_log_push(). The -Werror gcc option may be incompatible with NRF_LOG_ functions.

Children
Related