Hi All,
I have a problem using DbgConsole_Printf for printing negative floats on a custom board using mcuxpresso IDE 11.8 and mcuxpresso SDK version 2.12.
I have isolated the problem and see the same behavior with the demo projects on an lpcxpresso55s36 eval-board with the newest IDE and SDK versions. I went through a bunch of posts but can't seem to solve the problem.
How to reproduce the problem:
Using mcuxpresso IDE 11.9.0 open "Import SDK example(s)"...
select lpcxpresso55s36 board.
select the "hello_world" project under "demo_apps" and click next.
Check the box "Redlib: Use floating point version of printf" and leave other settings at default values.
I have modified main() by adding 4 lines using PRINTF.
PRINTF("hello world.\r\n");
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);
All five lines print. However, the negative floats are printed without a minus sign and with incorrect characters. The output is:
hello world.
12.340000
12./40000
1.000000
1.//////
The error seems to arise in "DbgConsole_ConvertFloatRadixNumToString" when it scans through the digits of the negative fractpart.
Please let me know if I need to provide more information.
How do I use the debug console with negative floats?
Kind regards Lauge
已解决! 转到解答。
Hi, @laugechristense
Thank you for your reply. Yes, the PRINTF() function should be used frequently in projects, and for floating negative types you can use the printf() function first.
Best regards, Alex
Thank you @Alex_Wang
I got your solution to work. As far as I can see, your code avoids the SDK debug_console. Should it just not be used in general?
Kind regards Lauge
Hi, @laugechristense
Thank you for your reply. Yes, the PRINTF() function should be used frequently in projects, and for floating negative types you can use the printf() function first.
Best regards, Alex
Hello, @laugechristense
You can try it out by following these steps:
1. Add #include "stdio.h":
2. Set macro definition SDK_DEBUGCONSOLE_UART=1, right-click project -> Open the properties window and refer to the following image:
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);
The results are as follows:
Best regards, Alex