Adsp BF 533 serial learning UART serial communication learning

Source: Internet
Author: User

Http://blog.chinaaet.com/detail/25424.html

 

Continue to learn the serial communication of ADSP-BF533 today, UART (Universal Asynchronous Receiver ER/transmitter (UART) Port) interface, is a full duplex universal serial interface, composed of RX and TX two lines, the extended RS232 chip can communicate directly with computer serial ports, which is usually used as the command and data communication interface for debugging.

As an asynchronous serial communication, the serial port of ADSP-BF533 can be configured as follows:

1. 5-8-bit data bit;

2. 1, 1 digit, or 2-digit stop position;

3. odd or even verification or not verification;

The baud rate of serial communication can be calculated using the following formula:

Baud Rate = sclk/(16 * divisor)

Sclk indicates the system clock frequency. The divisor value ranges from 1 to 65536.

The data transmitted through the serial port requires at least one start bit and at least one stop bit, and then returns an available check bit. The length of each data is about 7-12 characters. The format of the transmitted data frame is controlled by the uart_lcr register. Generally, the data is sent and received starting from the bytes LSB, as shown in:

 

Just like learning SCM, before using the serial port function of ADSP-BF533, we still first understand the functions and usage of each register related to it. Each register is described as follows:

1.Uart_lcr register: Line Control Register (uart_lcr ).

This register is a line control register used to control the format of transmitted data frames. Including the length of the Data bit, the length of the stop bit, and the setting of the check bit. The specific description of the Register is shown in:

2.Uart_lsr register: Line Status Register (uart_lsr)

This is a line status register used to obtain the status of each flag in the serial communication process. The specific descriptions are as follows,

The most common ones are 5th-bit thre and 1st-bit dr,

The 5th-bit value is used to determine whether the data register thr is null,

If this bit is 1, the data has been sent out.

The 1st-bit value is used to determine whether the UART receiving cache register has received new data. If it is set to 1, the data has been received. Other BITs can also be used to determine the status, such as frame errors and Verification Code errors.

 

3.Uart_thr register and uart_rbr register

Transmit holding register (uart_thr), The Receive Buffer register (uart_rbr ),

These are transmission data registers and receiving cache registers respectively,

Uart_thr is used to store data when the serial port is sent, and uart_rbr is used to receive data when the serial port is received.

 

4.Uart_ier register: Interrupt enable register (uart_ier ).

This register is a serial interrupt enable register. The register details are shown in. The 0th-bit and 1st-bit registers are used to enable the reception interrupt enable and sending interrupt enable of the serial port respectively.

5.Uart_gctl register:

This register is a serial global control register. The specific description of the Register is shown in. 0th bits and 3rd bits are used more often, and 0th bits are used to enable the internal serial clock, 3rd bits are used to control the status of the serial communication interface when it is idle.

 

6. uart_dll registers and uart_dlh registers:

These two registers are very important. They are used to set the baud rate of serial communication. The calculation formula is as follows:

Baud Rate = sclk/(16 * divisor ),

Divisor is the DL value, while DL = uart_dlh <8 | uart_dll.

The following is a calculated baud rate table provided by the official software. The system clock is 100 MHz:

 

Based on the data in the above table, we can also verify the calculation formula. In the last example, the system clock is 100 MHz and the baud rate is 6250000. Based on the formula DL = 100000000/(16*625000) = 1. The formula is correct.

// Xxx ××××××××××××××××××××××××××××××××××××××××××× *

// Xxx ××××××××××××××××××××××××××××××××××××××××××× *

After the first understanding of the serial port of ADSP-BF533, continue to learn its usage. The ADSP-BF533 processor provides 1 universal asynchronous receive/send (UART) port, which is fully compatible with PC standard UART. The UART port provides a simplified UART interface for other peripherals or hosts and supports full-duplex asynchronous serial data transmission with DMA capabilities. The UART port supports 5 to 8 data bits, 1 or 2 Stop bits, non-validation, odd verification, and even verification bits. The following describes how to use UART in terms of hardware and software.

First of all is the hardware circuit connection, the serial circuit of the ADSP-BF533 is basically the same with the single chip microcomputer, 1 shows, in the BF533 Chip Pin, there are two dedicated Serial Port IO Tx and Rx, then, in Figure 2, the two pins are converted to the computer level through a level conversion chip maxcompute, and then connected to the output port DB9. Then we connect the DB9 port and the computer serial port through a serial line, you can perform serial communication.

Figure 1

See figure 2. We can also see that when BF533 sends data to the serial port, the data is sent to the Tx pin, and then the chip is converted to rs232_tx, the data on rs232_tx is connected to the RX pin of the PC through the serial port crossover line to be received by the PC. Note that the serial port crossover line must be used to connect the BF533 serial port to the PC. Similarly, when the PC sends data, the data starts from the Tx pin on the PC and goes through the crossover line to reach the rs232_rx pin. Then, the data is converted to the RX signal through maxcompute and received by BF533. The above is the whole process of serial communication between ADSP-BF533 and PC.

Figure 2

The next step is the design of the serial communication software program.

1. The first is the serial port initialization function. The following is the serial port initialization program of BF533:

Void uartinit (unsigned short Div)

{

* Puart_gctl = 0x0009; ---- (1)

* Puart_lcr = 0x0080; ---- (2)

* Puart_dll = div; ---- (3)

* Puart_dlh = div> 8; ---- (4)

* Puart_lcr = 0x0003; ---- (5)

* Puart_ier = 0x0001; ---- (6)

}

Through the previous study of various registers on the serial port, we can easily understand the role of each statement. The role of sentence 1st is to enable serial clock, and when the serial port is idle, the serial line is pulled up; the sentence 2nd means that dlab is equal to 1, that is, access to uart_dll and uart_dlh registers is allowed; 3rd and 4th are the DLL and DLH registers are assigned values, the serial port baud rate is set, for the baud rate calculation formula, can refer to the previous article (ADSP-BF533 serial communication learning ); the purpose of clause 5th is to set the data bit of the serial communication to 8 bits, the stop bit to 1 bits, no verification, and then clear the dlab bits after setting the baud rate, this allows access to uart_thr, uart_rbr, and uart_ier registers, which is very important in subsequent data transmission and receiving. The last sentence is to allow the serial port to receive interruptions.

2. The next step is the serial port sending program, which is BF533 as follows:

Void test_tx (void)

{

Int I;

For (I = 0; I <50; I ++) // sends the test function to send the generated data through IR.

{

* Puart_thr = txbuf [I]; ---- (1)

While (! (* Puart_lsr & 0x0020); ---- (2)

}

}

The serial port sending procedure of BF533 is very simple. You only need to assign the data value to the uart_thr register and then determine the 6th-bit thre bit of the serial port status register uart_lsr, this bit is used to determine whether the Thr register is empty. When the register is empty, thr is set to 1. In the first sentence, we know that when the register is empty, the program will exit the while loop to continue sending other data.

3. Finally, it is the serial port receiving program. The serial port data receiving is generally achieved through serial port interruption. The following is the serial port receiving interrupt program:

Ex_interrupt_handler (uart_isr)

{

If (* puart_lsr & Dr) // determines whether new data exists.

{

Rxbuf [cont] = * puart_rbr;

Cont ++;

}

}

When the BF533 receives data, if an internal enabling serial port can receive the interruption, the system will automatically enter the interrupt processing function. after entering the function, first, judge whether the 1st-bit Dr bit of the serial port status register is 1. If this bit is 1, it indicates that new data is saved on the uart_rbr register, and then the data will be received and stored, that is, the data on the uart_rbr register is stored to receive serial data. It seems to be simpler than a single-chip microcomputer. After receiving the serial port data, the 51 single-chip microcomputer has to clear the interrupt flag, but the BF533 does not, so I checked the official BF533 documents and found the following sentence:"
Break interrupt (BI), overrun error (OE), parity error (PE) and framing error (FE) bits are cleared when the UART line Status Register (uart_lsr) is read. the data ready (DR) bit is cleared when the UART Receive Buffer register (uart_rbr) is read. "indicates that the interrupt flag, overflow flag, check bit error flag, and frame error flag are cleared after the serial port status register uart_lsr is read. The dr-bit is automatically cleared after the uart_rbr register is read. Based on the above principles, the BF533 serial port read/write program is very simple.

So far, the study of BF533 serial communication has come to an end.

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.