Uart embedded c program12/31/2022 ![]() ![]() ![]() In fact, the UCA0RXBUF register can be considered a FIFO of depth 1 (depth of ‘n’ means ‘n’ elements fits in the FIFO) which drops the oldest data once full. Using a FIFO to queue received data is very common. There are different types of FIFOs so I won’t cover all the possible designs, but we will look at one in detail shortly. If the FIFO is full and there is another piece of data to enter, it is either dropped (the newest data is lost) or the oldest data in the FIFO is pushed out and discarded. A FIFO is a type of buffer (or queue) in which the data enters and exits in the same the order. The solution is twofold: detect incoming data using interrupts rather than polling and then store each received character in a first-in-first out (FIFO) buffer. ![]() If the software does not read the data out of the register before the next character is received, the value in the register will be overwritten. What happens here is each character received by the peripheral is placed into the UCA0RXBUF register. You will notice that characters are dropped, only one or two of the characters are echoed back. Try typing ‘1234’ quickly at the menu prompt. Compile the code with this delay and then run it. This delay is exaggerated but it demonstrates an important point. The menu_run function reads the UART input and is then delayed one second before checking for the next character. We can easily simulate this scenario by adding a big delay into the the main loop – say one second – by using the _delay_cyles function. Once we start adding in more functionality to the main loop, it is possible that characters may be missed because the CPU is busy doing other things. As we learned with the push button back in lesson 6, this is not the optimal solution for most drivers. In the last lesson, we created a very simple UART driver which polls the peripheral for received data. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |