Although it is an LPC, the hardware principle of uart fifo is clear.

Source: Internet
Author: User

Experiences in using the lpc2000 UART serial port
In view of some problems of zgpswh in the use of serial ports, I summarized my understanding in the previous stage, which is relatively one-sided. If not, please correct them.

1. The serial port receiving module of the lpc2000 series chip includes the receiving buffer register and shift register. After the received data enters the shift register, the data is transferred to the buffer register in parallel through the shift processing. In fact, the uart fifo is a hardware ring Buffer Queue, which is physically unaddressable and invisible, only the FIFO egress of u0rbr is visible. U0rbr is the first to receive FIFO data. The length of the FIFO is configurable, also known as the trigger point. Strings smaller than this length will not cause interruption. However, in practice, it is impossible to read data from the serial port. The total length is an integer multiple of the trigger point value. Therefore, CTI is introduced, that is, the character receiving timeout interrupt. When there is a string read that is not specified in the trigger point value, the interrupt will occur. It has the same priority as the serial RDA interrupt, and will be enabled at the same time.
So how does the uart mechanism of the lpc2000 determine the one-time capacity of data read from the serial port? If the receiving FIFO contains 1 character, it can wait for the next character to be read within a certain period of time. That is to say, the CTI interruption will not be triggered if it does not exceed a certain period of time, this time is the time used to receive 3.5 to 4.5 Characters Under the communication protocol settings. For example, the serial port must receive a string consisting of 22 characters, OK _info_waitingfordata, returned after the GPRS data transmission status is successfully established. The FIFO trigger point is set to 14, after the first 14 characters are read, immediately trigger the RDA interrupt, jump to the RDA interrupt service subprogram to put the 14 characters in the preset buffer, and then read the last 8 characters, then the CPU is not immediately interrupted, it needs to wait for the time it takes to receive 3.5 to 4.5 characters (calculated based on the baud rate and frame format) when the serial communication protocol is set, the CTI interruption is triggered immediately. In other words, when the wait time is exceeded, the CPU considers that a complete string has ended. This is the true meaning of the string timeout.

2. Why should I use FIFO? I personally think it is mainly to improve the efficiency of serial port utilization and avoid packet loss to a certain extent. For example, if the trigger depth is set to 8 when a FIFO interrupt is sent through a serial port, the receiving interruption occurs only when the FIFO contains 8 characters, but not 8 bytes, this is because the frame header and frame end are added to the Serial Asynchronous communication protocol, but the appearance is still in character units. When sending, It is interrupted once when the FIFO contains less than 8 characters. Therefore, when sending the FIFO, you must create a buffer pool for serial port sending, in the sending interrupt service program, the number of data in the sending buffer is sent to the FIFO. The trigger depth is set to 8, and 15 characters are sent to the FIFO at a time, after the first batch of 15 characters are sent, the serial port starts to send automatically. When the first batch contains only 7 characters, the serial port is immediately interrupted. Therefore, in the sending interrupt service program, a counting pointer should be set as the upper limit for jumping out of the interrupt, which is not 8 but 15. In my opinion, to achieve FIFO efficiency, you must create a ring linked list of the Self-configured buffer zone, that is, you do not need to shift the data headers left in the Self-configured buffer zone. Zlg has a detailed queue-based routine.

3. In my opinion, when the trigger depth of FIFO is set to 1, the effect is the same as when the trigger depth of FIFO is not used.

4. When sending a serial port, it is recommended that the first character be sent before the serial port is opened, otherwise it may be interrupted only once. For example, the following function is used to interrupt the sending string through a serial port:
/*************************************** **************************************** *********************
** Function name: uart0_sendstr ()
** Function: Send a string to a serial port.
** Entry parameter: the first address pointer of the string to be sent by Str.
** Exit parameter: None
**************************************** **************************************** *********************
Void uart0_sendstr (char const * Str)
Str_send_p = STR;
U0thr = * str_send_p ++;
U0ier | = 0x02; // interrupted development
Processing in the interrupt sender program is:
Switch (IIR & 0x0e)
Case 0x02: // use the serial port to send an interrupt and send a string
If (* str_send_p )! = '/0 ')
U0thr = * str_send_p ++;
U0ier & = (~ 0x02); // indicates the sending interruption.
The principle of this practice is not clear, but the experiment proves that if you do not do this, you only send it once.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.