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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

890 Views
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!


Labels (1)
Tags (1)
0 Kudos
Reply
5 Replies

877 Views
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 Kudos
Reply

854 Views
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 Kudos
Reply

838 Views
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 Kudos
Reply

815 Views
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 Kudos
Reply

778 Views
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 Kudos
Reply