Uart write problem

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

hi,

   

I have a problem with uart_writetxdata().I have attached the code. The problem is UART is not able send all the digit as per the code.

   

the first line in for loop print four times on serial terminal. I have attached a pic of serial terminal.

   

Thanks in advanced

0 Likes
7 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

WriteTxData() does not check for status (Tx Buffer free), so you constantly overwrite the transmitter. Better use PutChar(). See datasheet.

   

Your conversion algorithm is not correct, use Number + '0' to convert a digit between 0..9 to ASCII.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

oh thanks

   

The thing is PutChar takes longer time to transmit.. Can i reduce the loop time for transmitting data(say 4 to 8 bytes) through uart ?

   

Why does PutChar takes more time with increase in number of digits in number? The comparision of buffer should take equal time for any number of digit. am i right?

0 Likes

PutChar takes longer since it actually waits for the character to be transmitted. Not doing so is naturally faster since just overwrites the output FIFO.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Set the Tx buffer size to 100 and call CyGlobalIntEnable; This will help for the moment until the buffer gets filled. Transmitting is automatically done in background interrupt driven.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thank you..

   

Is there any way to check the current buffer size?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The current buffer size is set in UART configuration dialog and cannot be changed by the program. You can check how many bytes already are in the buffer: Search in UART datasheet for TxBufferSize. This function returns number of bytes, not the size of the buffer as the name may suggest.

   

 

   

Bob

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

How about using sprintf(buffer, "character: %c",c);
    UART_UartPutString(buffer);
    NewLine();

   

It would make the program simpler. or use this

   

 sprintf(buffer, "string: %s",s);
    UART_UartPutString(buffer);

   

Or this

   

sprintf(buffer, "unsigned decimal: %u",u);
    UART_UartPutString(buffer);

0 Likes