EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: basantab on December 08, 2018, 02:34:14 am

Title: Stm32 converting float/int into string and pushing it to screen(need suggestion)
Post by: basantab on December 08, 2018, 02:34:14 am
Hello
I am using 4D system screen(lets say some screen) with stm32. And it has inbuilt library function of putstr(). I am taking adc data(voltage) to stm32 and converting it and pushing it into screen. The problem is it does have putCH function but doesnot work if i push number using that but how ever using putstr function it can push string in screen which leaves me to use this function by converting integer (actually float) into string and then use this function to push.

I would be glad if i was able to convert decimal number(float) into string and push it into screen.

but however this code below can at least convert integer into str (without decimal sadly).

Code: [Select]
char buffer[10];
  int x = 3333;  //voltage for example

  snprintf(buffer, 10, "%d", x);

  putstr(buffer);    //function that prints str frm Lcd library
  HAL_Delay(2000);

the above works for integer.

I tried floating point numbers this way but it doesnot print it. probably my floating point conversion is not correct.

can anyone suggest conversion regarding floating point conversion ?

I would really thank your name if i am able to solve that..



Title: Re: Stm32 converting float/int into string and pushing it to screen(need suggestion)
Post by: SiliconWizard on December 08, 2018, 03:43:49 am
The *printf() functions do not support floating point by default on those targets, and that's probably the problem you're running into.

You can refer to the following thread for solutions: https://www.eevblog.com/forum/microcontrollers/stm32-smbus-and-sprintf-with-floats (https://www.eevblog.com/forum/microcontrollers/stm32-smbus-and-sprintf-with-floats)
Title: Re: Stm32 converting float/int into string and pushing it to screen(need suggestion)
Post by: richardman on December 08, 2018, 08:59:44 am
It depends on whether you are using nanolib, or plain newlib, and that depends on how you set up your makefile or IDE etc. basically linker flags.

newlib supports %f/%g etc. by default.

nanolib does not by default and you need to explicitly enable float capable printf.

A couple checkbox in our IDE, translated to a handful of different scenarios.
Title: Re: Stm32 converting float/int into string and pushing it to screen(need suggestion)
Post by: nctnico on December 08, 2018, 11:15:37 am
I'd strongly recommend to find a minimal vuprintf (the mother function of all printfs) and if necessary add floating point printing to it. I went down this road for a recent project and this route was the most sane one because even newlib nano pulls a lot of junk into the project. There is nothing nano about it.