Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12453 Discussions

How to convert float to string for UART transmission

APena7
Beginner
395 Views

I'm trying to send a floating point number (it's the ratio of two measurements the device makes) via UART to a terminal program (Termite). However, I understand that the printf function for nios ii does not support transmission of floats. Is there a convenient way to send this floating number? I have tried converting to a string using ftoa, gcvt and sprintf, but none of these solutions compile/work.

 

As an example, here are a few methods I've tried (though in the real code, only one method is uncommented):

 

sprintf(BER_s,"%4.2f" ,BER); ftoa(BER,BER_s,3); gcvt(BER,3,BER_s);   printf("BER: %s \n", BER_s);

Where BER is the float I wish to print, and BER_s is a char array - char BER_s [20];

 

Thanks in advance for your suggestions.

0 Kudos
1 Reply
Ahmed_H_Intel1
Employee
283 Views

Hi,

If it is a number why you don't transfer it to integer and print it?

You can simply use:

int(float BER);

Regards,

 

Reply