/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / How to convert float variable to char

Username:     
Password:     
             

Forum

# 1   2008-12-04 07:41:44 How to convert float variable to char

lebkrut
New member
Registered: 2008-12-04
Posts: 2

How to convert float variable to char

I use mcu STM32F103RBT6 for get analog voltage from PA1 for show on LCD. Then I need your help how to convert float variable to char.
My program is below :

float fVal;
char cVal[5];
int main(void)
{
  ..
  ..
  while(1)                                                 
  {
     fVal = (GetADC1Channel(ADC_Channel_1)*3.3)/4096;
     sprintf(cVal,"%.7f",fVal);
     ..
     ..
  }
}

Compilation result
Running : LD
\"C:\Program Files\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -mcpu=cortex-m3 -mthumb  -Wl,-T -Xlinker "D:\Projects_X\uController\ET-STM32F103\Source code\ADC_LCD\project\RIDE\hex\Project.elf.ld" -u _start -Wl,-static -Wl,--gc-sections -nostartfiles -Wl,-Map -Xlinker "D:\Projects_X\uController\ET-STM32F103\Source code\ADC_LCD\project\RIDE\lst\Project.map" 
C:\Program Files\Raisonance\Ride\Lib\ARM\e_stdio_thumb.a(_sp_puts.o): In function `_SMALL_PRINTF_puts':
_sp_puts.csad.text+0x48): undefined reference to `__io_putchar'
C:\Program Files\Raisonance\Ride\Lib\ARM\e_stdio_thumb.a(_sp_puts.o): In function `puts':
_sp_puts.csad.text+0x70): undefined reference to `__io_putchar'
collect2: ld returned 1 exit status

Build failed


   I waiting for your help, best regards
Ratchapol Lebkrut

Offline

 

# 2   2008-12-05 13:33:31 How to convert float variable to char

VincentC
Administrator
Registered: 2007-11-08
Posts: 149

Re: How to convert float variable to char

Hi,

The function __io_putchar is in the UART0_putchar library, and it is required when using the small printf library.
Please check in your linker project options that this library is included.

Also, considering that you want to use printf for displaying floats, you must make sure that you are NOT using the "no float" version of printf. (in the linker/libraries options as well)

And finally, of course, you must #include <stdio.h>

If these hints do not help to solve your problem, then I will need you to send me a complete project. zip it and email it at this email address:
support@raisonance.com

Best Regards,

Vincent

Offline

 

# 3   2008-12-08 14:32:47 How to convert float variable to char

lebkrut
New member
Registered: 2008-12-04
Posts: 2

Re: How to convert float variable to char

Now I can solve my problem by set Project -> Properties -> LD Linker -> Libraries ->UART0 putchar = Yes,small printf = yes. Thank you for your help VincentC.

Offline

 

Board footer