sprintf (MyVar, "%f", float_data)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

I am having a problem writing a floating point value to the UART. I read about an issue at the link below, and my problem likely is related somehow .

   

http://www.cypress.com/?app=forum&id=2492&rID=86619

   

The problem is that the UART terminal does not respond at all when attempting to write floating point data to it. This happens even if you set the compiler to not use the nano libraries.

   

I know my UART setup is working because integers and ASCII strings print flawlessly.

   

Thanks for any suggestions or workarounds.

0 Likes
8 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Info is a bit short, what is the definition of MyVar? Better post your complete project.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Here is the project. What it does is it monitors the mains voltage and periodically generates peak and RMS voltage reports.

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

this should work

   

odissey1

   

 

   

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

   

#if defined (__GNUC__)
    /* Add an explicit reference to the floating point printf library */
    /* to allow the usage of floating point conversion specifiers. */
    /* This is not linked in by default with the newlib-nano library. */
    asm (".global _printf_float");
#endif
 
      char strMsg1[64];//output UART buffer
      ...
      sprintf(strMsg1, "%f", 0.01); 
      UART_1_PutString(strMsg1);

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Have a look at this thread www.cypress.com/ Robyn explains the why and how2.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I tried the above sugessions. The UART is still not printing the data. What is going on? It worked just fine prior to release 3.0.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Kind of a wild guess: try to increase the head size for your project. There were reports that the 128 bytes its now set to by default might be too small.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

See also http://www.cypress.com/?app=forum&id=2492&rID=70447&start=21 (right at the bottom) - the heap size seems to be the solution.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I adjusted the heap size and that fixed my original problem. I now am having a new problem. The UART arbitrallarly simply just stops writing floating point data to the UART.

   

I was thinking the interrupt was the cause, but I took it out of the loop. Same problem.

   

Is there a memory leak or something going on?

   

My updated project is attached.

0 Likes