NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » How to know data has finished received from UART?
April 02, 2013 by oshjdf |
I'm trying to code a simple program that display string I enter at pc terminal on LCD. e.g. Mom, I love you. But, how to know data has finished received from UART so it can be displayed at LCD? |
---|---|
April 02, 2013 by Ralphxyz |
Hi oshjdf, one method is to put a EOL character at the end of the line: So you might have Mom, I love you.~ You could actually use the period instead of the tilde. Or you could do a character count every sixteen characters send to LCD. Ralph |
April 02, 2013 by pcbolt |
oshjdf - One of the more reliable ways of doing UART reads is with interrupts. Whenever a character is ready on the receive line (RX) an interrupt can be set up to simply read the character and copy it to a data array or buffer. Then the main part of the program can just sit around and wait for a change in the buffer and output the character to the LCD one at a time. When the data from the PC stops, the main program just sits and waits again after outputting to the LCD. Here is a simple interrupt code segment:
In the main part of the code I have another buffer pointer or index variable "rx_out_idx" that I test against "rx_in_idx".
You have to do some setup for the interrupt and the global variables, but that's not hard. |
Please log in to post a reply.
Did you know that you can follow NerdKits on Facebook, YouTube, and Twitter? Learn more...
|