Display float value using sprintf not working

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

cross mob
Anonymous
Not applicable

Hi,

   

i would like to display the results of a division as a float using sprintf and display it using the UART communication component.

   

My code is give below.

   
    

 

   
   

float ft,db;

   
    char buffer[20];   
   
        
   
    db=9.9*3.141;    
   
    sprintf(buffer,"value=%f\n\r",db);   
   

UART_UartPutString(buffer);        

   

 

   

I don't get any value at all on my terminal program.

   

Just 

   

value=

   

I am unable to understand how to display float values using sprintf.

   

I am using PSOC Creator 3.2

   

thanks

   

a

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

3 steps to success:

   

Update to latest Creator 3.3 CP3

   

under Projects-> Build Settings -> Linker: Set Use newlib-nano float formatting to true

   

in .cydwr view (where you set the pins) "System"-tab: set Heap size to 0x0200

   

 

   

Bob

Same problem with PSOC 5LP, increasing heap size finally solved the problem.

 
0 Likes
Anonymous
Not applicable

thanks for the quick reply, its working in 3.3, I am able to get the float values displayed.

   

However there is a problem in the PSOC Creator 3.3 CP3 software.

   

I have noticed that changes to the font size and style do not get saved, they keep getting back to the default setting.

   

Also the recent projects list is not updated, no recent projects are displayed. Also the software startup is very slow.

   

All the above problems surfaced suddenly after the program froze, and I had to restart the computer.

   

However thanks for your help, I realize I may have to raise a support ticket or something.

   

thanks

   

a

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

You are low on resources on your computer Or it is a very slow processor clock.  Try to reinstall the software again.

0 Likes