- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello friends,
This is first time that i wrote question on community , pls understand and let me know if there is something not enough
I am testing an ADC with PSoc 4 pioneer Kit ( CY8CKIT-042 ) and i think measuring the value is successful, but i can't print float to UART
first i'll add my code
#include "project.h"
#include "stdio.h"
float32 adout ;
uint32 channel ;
int16 output;
float32 vo ;
char arr[20] ;
char vo_arr[20];
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start();
UART_UartPutString( " ADC TEST START ! \n" );
ADC_Start();
ADC_StartConvert();
for(;;)
{
if( ADC_IsEndConversion(ADC_RETURN_STATUS) == 1)
{
output = ADC_GetResult16(channel);
sprintf(arr, "ADout : %d\r\n" , output );
UART_UartPutString(arr);
vo = ADC_CountsTo_Volts(channel, output);
sprintf(vo_arr, "Vout : %f\r\n" , vo );
UART_UartPutString(vo_arr);
CyDelay(2000);
}
}
}
This code gives me this outuput on the monitor
So i tried Debug and check the variable , and add some screenshot below
I think everything is perferct except, putstring(float) , what should i have to do ?
Solved! Go to Solution.
- Labels:
-
ispn:39611:1:0
-
l1:314:1:0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I usually use following method to print float value in MCU program
======
sprintf(str, "(int format) %d.%02d ", (int)fvalue, ((int)(fvalue * 100.0 + 0.5))%100) ;
UART_UartPutString(str) ;
======
But in the community someone taught us that there is a linker flag for floating format
So I tried with following program
=======================
#include "project.h"
#include <stdio.h>
char str[128] ; /* print buffer */
int main(void)
{
float32 fvalue ;
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
sprintf(str, "Float Format Test (%s %s)\n", __DATE__, __TIME__) ;
UART_UartPutString(str) ;
for(;;)
{
for (fvalue = 0.0 ; fvalue < 10.0 ; fvalue += 0.01) {
sprintf(str, "(int format) %d.%02d ", (int)fvalue, ((int)(fvalue * 100.0 + 0.5))%100) ;
UART_UartPutString(str) ;
sprintf(str, "(float format): %.2f\r\n", fvalue) ;
UART_UartPutString(str) ;
CyDelay(1000) ;
}
}
}
=======================
With "Use newlib-nano Floating Formatting = False",
Naturally the result was
Then I tried with "Use newlib-nano Floating Formatting = True"
The result was
First the good news was that when fvalue = 0.0, yes it printed "0.00".
Second the bad news was that when fvalue = 0.01, program crashed and ran to exception.
Probably I was missing some other necessary step(s) to make floating point work,
but since my usual method is serving me enough, I resigned here.
So for my conclusion, it's safe using the method I wrote at the beginning.
==========
sprintf(str, "(int format) %d.%02d ", (int)fvalue, ((int)(fvalue * 100.0 + 0.5))%100) ;
UART_UartPutString(str) ;
==========
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I usually use following method to print float value in MCU program
======
sprintf(str, "(int format) %d.%02d ", (int)fvalue, ((int)(fvalue * 100.0 + 0.5))%100) ;
UART_UartPutString(str) ;
======
But in the community someone taught us that there is a linker flag for floating format
So I tried with following program
=======================
#include "project.h"
#include <stdio.h>
char str[128] ; /* print buffer */
int main(void)
{
float32 fvalue ;
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
sprintf(str, "Float Format Test (%s %s)\n", __DATE__, __TIME__) ;
UART_UartPutString(str) ;
for(;;)
{
for (fvalue = 0.0 ; fvalue < 10.0 ; fvalue += 0.01) {
sprintf(str, "(int format) %d.%02d ", (int)fvalue, ((int)(fvalue * 100.0 + 0.5))%100) ;
UART_UartPutString(str) ;
sprintf(str, "(float format): %.2f\r\n", fvalue) ;
UART_UartPutString(str) ;
CyDelay(1000) ;
}
}
}
=======================
With "Use newlib-nano Floating Formatting = False",
Naturally the result was
Then I tried with "Use newlib-nano Floating Formatting = True"
The result was
First the good news was that when fvalue = 0.0, yes it printed "0.00".
Second the bad news was that when fvalue = 0.01, program crashed and ran to exception.
Probably I was missing some other necessary step(s) to make floating point work,
but since my usual method is serving me enough, I resigned here.
So for my conclusion, it's safe using the method I wrote at the beginning.
==========
sprintf(str, "(int format) %d.%02d ", (int)fvalue, ((int)(fvalue * 100.0 + 0.5))%100) ;
UART_UartPutString(str) ;
==========
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I found following two threads
https://community.cypress.com/message/44036#44036
https://community.cypress.com/thread/31761?start=0&tstart=0
So I did
(1) Linker option
(2) Linker Command
(3) Expand heap
Edit Generated_Source / cyfitter.h
CYDEV_HEAP_SIZE from 0x80 -> 0x200
Then the result was
So for the first time, I could make "%f" work.
(Although I'd rather stick with int format method)
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello TanaKa
I really appreciate for your reply, your solutions worked for me
but for me , basic option for "Use newlib-nano Floating Formatting was false , and i tried to change it to true , mcu also goes to crash as your one does,
i think your sprintf argument will be best fit for me,
Thank you very much,
Regard Bongjin,