- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,all
I want to use the Printf () function to print the serial port information.
For example:
Normal:
UART_SpiUartPutArray("Helon Test\r\n",sizeof("Helon Test\r\n"));//Uart can print the serial port information.
Now,i want to do like this:
printf("Helon Test\r\n");//"Helon Test\r\n" receviced by serial tool.
so,my question is how can i do to print the serial port information by printf() function?And the _Write () function has been rewrited,but printf("Helon Test\r\n") still can't print the serial port information.the _Write () function as follow:
int _write(int file, char *ptr, int len)
{
int i;
file = file;
for (i = 0; i < len; i++)
{
UART_SpiUartWriteTxData(*ptr++);
}
return len;
}
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, but when using printf() it must call your new _write() function sooner or later. So when you set a breakpoint there, you can find out whether its called at all (then something in your code is wrong) or not (then its not the rioght way to change printf).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you debug your project, is your _write() function called at all?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,hli
if the _Write () function has been rewrited,the linker will be link the New _Write () function instead of the Old.So i do nothing with it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, but when using printf() it must call your new _write() function sooner or later. So when you set a breakpoint there, you can find out whether its called at all (then something in your code is wrong) or not (then its not the rioght way to change printf).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,hli
you are right,when set a breakpoint in new _write() function,it has not been called.So how to set the project?And the new _write() function is ok,can you give some ideas?
Million thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,hli
I find the cause of the problem is the Heap Size(bytes) is too small.Previous value is 0x80, I changed to 0x200,Now i can use printf() function print serial port information.I have not changed anything, just change the Heap Size(bytes).
Thanks for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,Helon_chen_1478911
Can you share your demo for me please, I have some problem for printf() function, and i change the Heap Size to 0x200, but the printf() function print any thing……
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, Eric!
Easiest is to use sprintf(Buffer,...) and UART_PutString(Buffer). Your PSoC hasn't got an OS, so prinf() does not know where to send the data to. There is a solution by supplying an own function, but my experiences are that this consumes more resources and CPU time.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob
Thanks for your help!
I was use UART_PutString(Buffer) only can print string, and use sprintf(Buffer,...), it must use array[]; and i found iprintf(buffer), but it can print %s/%d/%c/%x only...
So i want to use printf(buffer) to print more, but it can not work.
Do you have a demo for printf() API? or
do you have any advice for it? thanks!
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
", and use sprintf(Buffer,...), it must use array[]" Tat is not quite right.
In the above case, "Buffer" receives the conversion of your formatted data, so you can use UART_PutString(Buffer).
try:
char Buffer[80];
int Data = 4277;
sprintf(Buffer,"Data is %d",Data);
UART_PutString(Buffer) ;
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi BOB
The problem is solved, thanks for your support!
Eric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome, Eric!
Bob