Author Topic: Stm32 converting float/int into string and pushing it to screen(need suggestion)  (Read 949 times)

0 Members and 1 Guest are viewing this topic.

Offline basantab

  • Contributor
  • Posts: 20
  • Country: fi
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..



 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 3214
  • Country: fr
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
 

Offline richardman

  • Frequent Contributor
  • **
  • Posts: 427
  • Country: us
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.
// richard http://imagecraft.com/
JumpStart C++ for Cortex (compiler/IDE/debugger): the fastest easiest way to get productive on Cortex-M.
Smart.IO: phone App for embedded systems with no app or wireless coding
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 17676
  • Country: nl
    • NCT Developments
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.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf