printf not working and, PRINTF of negative float adds a /

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

printf not working and, PRINTF of negative float adds a /

2,217 次查看
scoottroop
Contributor II

Hello! i'm currently working on a project which includes negative floats, its just data from a sinus wave that I want to print the data to see that it is correct before and after altering it. However, when printing, the negative float values have a / in front. I will show what I mean :  0

This is the code: 

for (int i = 0; i < 20; i++) {

PRINTF("%f\r\n", Sinus[i]);

}

and the outputted data is: note that the / replaces a value.


0.587780
0.951050
0.951050
0.587780
0
-0./87780
-0./51050
-0./51050
-0./87780
0
Using regular print does not work either.
Also, both of these are enabled:PRINTF_FLOAT_ENABLE=1
PRINTF_ADVANCED_ENABLE=1
I'm using a LPCXpresso55S69-EVK .
Some other old posts had problems with the fsl debug console file, but I'm too much of a noob to know what to look for in those files.  Is there any other way to check the data otherwise (I'm not the best at c), since I need to know that my data is not corrupted if I want to use it later (I'm going to perform interpolation with the data). 

Thanks in advance hope this post is somewhat clear!


标签 (1)
标记 (1)
0 项奖励
回复
5 回复数

2,204 次查看
Alex_Wang
NXP Employee
NXP Employee

Hi, @scoottroop 

       Please refer to the following link: Solved: Re: Printing negative floats with DbgConsole_Printf in mcuxpresso SDK 2.15 - NXP Community

       Hope this helps you.

Best regards, Alex

0 项奖励
回复

2,181 次查看
scoottroop
Contributor II

Thank you for the quick reply! However, it still does not work as intended. I still have the same issue with a / being printed as the first value after the decimal, like this : 
0.587780
0.951050
0.951050
0.587780
0
0./87780
0./51050
0./51050
0./87780
I'm using the latest version of the IDE. Any more information you need from me?

0 项奖励
回复

2,165 次查看
Alex_Wang
NXP Employee
NXP Employee

Hi, @scoottroop 

When you create a project, you need to set Redlib: Use floating point version of printf, as shown below:

Alex_Wang_0-1709774838642.png

1. Add #include "stdio.h":

Alex_Wang_1-1709775017975.png

2. Set macro definition SDK_DEBUGCONSOLE_UART=1, right-click project -> Open the properties window and refer to the following image:

Alex_Wang_2-1709775017984.png

3.Use the printf () function to print normally.

	printf("%f\r\n", (float) -12.34);
	printf("%f\r\n", (float) -12.34);
	printf("%f\r\n", (float) 1);
	printf("%f\r\n", (float) -1);

 If you have any questions, please share your project and I'll check it for you.

Best regards, Alex

0 项奖励
回复

2,142 次查看
scoottroop
Contributor II

Hey! i'm pretty sure that i did all these steps correctly, so ill send my project so that you can have a look. 
And how does the semihost hardfault actually work? Trying to use my functions gets me directly to the hardfault. However when using my code on different platform there is no problem, sorry for stupid questions I'm quite new to programming in general!

0 项奖励
回复

2,105 次查看
Alex_Wang
NXP Employee
NXP Employee

Hi, @scoottroop 

       Use the printf () function when printing floating-point numbers, and do not macrodefine CR INTEGER PRINTF.

       Please refer to the attached project.

Best regards, Alex

0 项奖励
回复