floating point

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

cross mob
Anonymous
Not applicable

 i want to print float value in hyperterminal? which statements i will use here?how to print float value?

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Assuming you are trying to print a float driven by PSOC, as mentioned before,

   

you use sprintf( ) with proper formatting command. sprintf( ) converts numeric

   

to a string, and places it into a buffer, null terminated. You then use UART API

   

to send char string to Hyperterminal. So declare a char buffer, say 10 - 15 characters,

   

and apply sprintf() to load it.

   

 

   

See attached doc for examples of formatting for sprintf( ).

   

 

   

Regards, Dana.

View solution in original post

0 Likes
10 Replies
Anonymous
Not applicable

To display a float value on hyperterminal, you need to first convert it into a string using sprintf function and then send it via UART.

0 Likes
Anonymous
Not applicable

 i converted into string and then iam displaying but it comeslike only integers use printf floating point FP u

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Assuming you are trying to print a float driven by PSOC, as mentioned before,

   

you use sprintf( ) with proper formatting command. sprintf( ) converts numeric

   

to a string, and places it into a buffer, null terminated. You then use UART API

   

to send char string to Hyperterminal. So declare a char buffer, say 10 - 15 characters,

   

and apply sprintf() to load it.

   

 

   

See attached doc for examples of formatting for sprintf( ).

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

 sprintf not printing anything.......

   

how to print floating point?

0 Likes
Anonymous
Not applicable

Take a look at this:www.cypress.com/

   

and this :www.cypress.com/

   

 

   

It contains information about printing floating point value.

   

 

   

Regards

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

sprintf() really does not print anything, but it stores the converted values in a string that can be printed or sent via UART or USBUART o a PC. When the format is a string residing in flash (as usual) you have to use csprintf().

   

 

   

Bob

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

Hi,

   

 

   

I know this is an old post but my issue is related and I'm quite hesitant to add another forum post with the same issue. I was wondering how to make sprintf work with my USBUART.

   

I am using the USB_PutString(reply_str) API . I had no issue displaying any string from my other functions however for my ADC, I would like to display the mV calculation in the hyperterminal.

   

 

   

I am using PSoC5 Pioneer Kit, I had connected my ADC pin to the VR so as I could emulate Voltage reading using the built in potentiometer of the kit. I had this tested first with the kit's LCD and I had no problem displaying the values. When I applied it in the hyperterminal, I not receiving any values. This is my code excerpt:

   

result = ADC_SAR_Seq_GetResult16(chan);
res = ADC_SAR_Seq_CountsTo_mVolts(result);
sprintf(reply_str, "%f mV", res);
while ( USB_CDCIsReady() == 0u ); 
USB_PutString(reply_str);

   

 

   

Basically, the way this project works is that the USB Host will issue a command and the Pioneer kit will reply with the GPIO State. I've attached here an example of GPIO state inquiry for Digital IO (Port 4, pin 3) and Analog IO (Port3,Pin1). 

   

For the digital pin inquiry, I was able to return the state. I was hoping to do the same for the ADC wherein I could display the value.

   

 

   

Thanks,

   

K

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

K,

   

not a good idea to post an "old" problem in a PSoC1 forum when related to PSoC5 😉

   

Make sure you are using the latest Creator 3.3 and latest components.

   

sprintf() needs some settings to work:

   

In "Project -> Build settings -> Linker" you'll have to set "Use newlib nano" and "Use newlib nano float formatting"

   

In .cydwr-view (where you assign the pins) under "System" tab set the heap size to 0x100, better 0x200.

   

 

   

Happy coding

   

Bob

Bob,  just wanted you to know I have been beating my head against the wall on this issue for several hours now... and then I found your post.   Problem fixed!! Thanks a bunch!  You saved me a fortune in Ibuprofen. 😉

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

Support your local pharma. I prefer Aspirin (Got my first education at BAYER)

   

;-))

   

 

   

Bob

0 Likes