Skip to main content
sreejithu4u
Associate II
December 7, 2012
Question

USART float values

  • December 7, 2012
  • 4 replies
  • 1106 views
Posted on December 07, 2012 at 17:08

hello,

ive been playing around with USART on my stm32f4 discovery for some time now. I am able to send letters and strings on USART but not float values. i really need to transmit float values to PC.I`ve tried but failed.used sprintf() also without luck..can anyone tell me how could i send float values over USART?

#usart
This topic has been closed for replies.

4 replies

Tesla DeLorean
Guru
December 7, 2012
Posted on December 07, 2012 at 18:52

How does sprintf() fail? Are you linking in a library that supports floating point via printf()?

On a simplistic level you could output the integer and fractional parts with some decimal math.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
sreejithu4u
Associate II
December 8, 2012
Posted on December 08, 2012 at 06:00

hi clive,

yes i`ve tried splitting number onto individual digits and sensing them converting to ascii characters.I`ve been using coocoxcoide 1.6..i guess ive added retarget printf option and the code,

float pi=3.1417;

char buffer[64];

sprintf(buffer,''%f'',pi);

int i=0;

while(buffer[i]!='\0')

{

   USART_SendData(USART1,buffer[i]);

   delay(0x000FFFFF);

}

but i dont get any output on terminal

Tesla DeLorean
Guru
December 8, 2012
Posted on December 08, 2012 at 14:43

Ok, the USART has a status register that indicates if it's empty (TXE), use it, and not arbitrary delays.

If you don't see output perhaps your not generating any string, you could brace the output of the string with '[' and ']' to confirm this. Use a debugger and look at the string.

If the CooCox default library and settings is not supporting floats in printf/scanf then find the settings and libraries to enable that. Read the documentation, access their support resources and forum.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
sreejithu4u
Associate II
December 8, 2012
Posted on December 08, 2012 at 17:41

@clive1

thanks man! i1l check it out thanks a ton

regards