[Original] Can I only read data from the serial port once on the lpc1114? Multiple times!

Source: Internet
Author: User

Initially, read the serial port data for processing as follows:

While (1)

{

Data = receivebyte ();

Switch (data)

{

Case 'A ':

Function1 ()...

Break;

Case 'B ':

...

Break;

Case 'C ':

...

Break;

Default:

Break;

}

}

In this way, the data can only be read once, and then how to write data to the serial port cannot be read.

Once it enters the display status, it is stuck in an infinite loop and cannot jump out. Refer to the lpc1114 manual to find information about the serial port.

When UART receives data, it can receive data in query or interrupt mode.

 

Table 4-1 how data is received

Query Method

The query register u0lsr [0] is used. As long as the data is received, the u0lsr [0] bit is set

Interrupt mode

1. Set UART interrupt enable register (u0ier) so that u0ier [0] = 1

2. Open System interruption

If the data in the receiving FIFO reaches the trigger point set in u0lsr, the interrupt-RDA is triggered.

If data is received but the number of received data is smaller than the trigger point, a character timeout interruption occurs after a period of time-CTI

 

When receiving data in the interrupt mode, if RDA is interrupted, the data can be read cyclically from u0rbr. If a character timeout interrupt occurs-CTI, you can use u0lsr [0] to determine whether the FIFO contains valid data.

Solution: You can use the interrupt mode to read data multiple times.

 

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: info-contact@alibabacloud.com 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.