- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Starting with the Example program UART_Tx01 I successfully printed its output to a Teraterm window. I used an FTDI USB to TTL Serial Cable.
But I would like to print floating point numbers to the terminal using printf. The project build okay using:
printf("Test printf function. float:%f \n",f);
where f is a float variable. But nothing prints on the terminal.
The LCD_Char_1_PrintInt8(count); function works fine but I want to format floating point output.
I am using the CY8KIT-050 and PSoC Creator 3.3
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Set "Use newlib nano Float Formatting" in project settings and increase heap size to at least 0x0200 bytes in .cydwr view, system tab.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Set "Use newlib nano Float Formatting" in project settings and increase heap size to at least 0x0200 bytes in .cydwr view, system tab.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Bob. I tried that but still no fprint to the Teraterm terminal. I increased heap size to 0x0800 in cydwr System tab. For future readers of this search, Bob is saying go to Project tab > Build Settings > Linker > General > Use newlib Float Formatting = True.
The only display in Teraterm terminal is the LCD_Char_1_PrintInt8(count); that displays on the LCD of the development board.
Attached is the project. The only change I made to the Example is to add the fprint statement in a loop. Oh. I also added #include <stdio.h> and included Build Settings > Linker > General > Additional Libraries > m
I cannot find any reference to this problem is the search results. Any help is welcome.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Baud rate of your UART is non-standard, use during test phase 9600 baud.
Let the UART handle the interrupt, set Tx buffer to 80 and uncheck other interrupt sources
Check connection of port P0_1 with plugs on P5 serial tx line (2)
You have not provided the needed _write() function for GCC. How should C know that you want to have print going to your UART and not to another device
/* For GCC compiler revise _write() function for printf functionality */
int _write(int file, char *ptr, int len)
{
int i;
file = file;
for (i = 0; i < len; i++)
{
PuTTY_PutByte(*ptr++); // send to your device
}
return len;
}
//***********************************************************************************//
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob, Your comment is quite helpful regarding "how should C know" where to direct print. I will experiment with this and close when I have a working model. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks again, Bob. I fixed it. I used sprintf() instead of printf() to print floating point to a string. Then I redirected output to UART instead of the LCD. I should have thought of that! I also added #include <string.h> but don't know if that's necessary So I have:
#define CR (0x0Du) // carriage return character
#define LF (0x0Au) // define line feed character
float f;
....
char num[] = "1.3456789012345"; // initialize the string to receive floating point data
char *p;
sprintf(num,"%-f", f); // convert floating to string left justified
p = num; // pointer to start of num string
/* The while loop will execute until a null end-of-string character is found */
while (*p) UART_1_WriteTxData(*p++); /* Sending the data */
UART_1_WriteTxData(CR); // write carriage return
UART_1_WriteTxData(LF); // write line feed
How do we mark an answer as "Verified?"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How do we mark an answer as "Verified?" I don't know, but I am quite content as long as you don't flag it as "offensive" 😉
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob, Thanks for your comment on increasing the heap size, it helped a lot. Jacek
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yeah usually strange behavior is indication to suspect on heap..
But for terminal window try http://docklight.de/ at least it is my favorite 🙂