Skip to main content
Visitor II
May 17, 2025
Solved

printf fail to print float type

  • May 17, 2025
  • 3 replies
  • 550 views

Software tool: IAR Workbench 9.60

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <intrinsics.h>

int putchar( int ch ){  
  while(!(USART2->ISR&0X0080));   
USART2->TDR  = (unsigned char)ch;
return ch;
}
 
test code:
printf("%d\n",ADC_array[0]);
printf("%f\n",1.234567);
 
Output on computer:
62615       ----correct
%f             ----incorrect(should output 1.234567)
    This topic has been closed for replies.
    Best answer by AScha.3

    check : project->properties->settings : use float with printf...

    AScha3_0-1747501069208.png

     

    3 replies

    Graduate II
    May 17, 2025

    Perhaps need to check box full scanf/printf libraries supporting floating point.

    Likely quite large so not enabled by default.

    AScha.3Answer
    Super User
    May 17, 2025

    check : project->properties->settings : use float with printf...

    AScha3_0-1747501069208.png

     

    STM32L09Author
    Visitor II
    May 18, 2025

    thank you, I found it in this window:

    STM32L09_0-1747530336194.png

    the default is Small, I change it to Full, now it works, I have float printed.

    63445
    1.234567

     

    by the way, will this configuration increase the hex fill? should I change it back to Small after debugging? so I can save the flash size.