Electronics > Microcontrollers

STM32CubeMX sprintf does not work with float

(1/2) > >>

ebclr:
I have those 2 similar routines, one to write an integer to the LCD and the other to write a float,  the integer ones work perfectly but the very similar one for float does not work, I'm guessing that sprintf fails for a float on stm32cubemx compiler, any tips on that?

void writeInteger(LiquidCrystal *lcd, int valueToBedisplayed, uint8_t MaxLenghtOfDigitis)
{
   char StringValue[MaxLenghtOfDigitis];
   sprintf(StringValue, "%d", valueToBedisplayed );
   size_t Lengh = strlen(StringValue);
   for (uint8_t i = 0; i < Lengh; i++){
      write(lcd ,*(StringValue+i));
   }
}



void writefloat(LiquidCrystal *lcd, float floatToBeDisplayed, uint8_t MaxLenghtOfDigitis)
{
   char StringValue[MaxLenghtOfDigitis+2];
   sprintf(StringValue, "%f", floatToBeDisplayed );
   size_t Lengh = strlen(StringValue);
   for (uint8_t i = 0; i < Lengh; i++){
      write(lcd ,*(StringValue+i));
   }

langwadt:
mcu settings:  -u _printf_float

peter-h:
Have a read around here
https://www.eevblog.com/forum/microcontrollers/is-st-cube-ide-a-piece-of-buggy-crap/msg4363183/#msg4363183

You can have lots of fun with the Newlib libc.a library and it's duff mutexes, its use of the heap, etc :)

In the end I replaced it with an open source one - all in the thread and here
https://www.eevblog.com/forum/programming/best-thread-safe-printf-and-why-does-printf-need-the-heap-for-f-etc/msg4325479/#msg4325479

DavidAlfa:
I remember some option in the compiler/linker whatever settings to enable floats in printf

DavidAlfa:
As I said, here it is

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version