You are here

Uart write problem | Cypress Semiconductor

Uart write problem

Summary: 7 Replies, Latest post by hli on 21 Oct 2016 01:21 AM PDT
Verified Answers: 3
Last post
Log in to post new comments.
creative's picture
User
43 posts

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

 

user_1377889's picture
User
9596 posts

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

creative's picture
User
43 posts

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?

hli
user_78878863's picture
User
2575 posts

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.

user_1377889's picture
User
9596 posts

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

creative's picture
User
43 posts

Thank you..

Is there any way to check the current buffer size?

user_1377889's picture
User
9596 posts

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

user_242978793's picture
User
1031 posts

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);

Log in to post new comments.