The difference between the sending identifier UDRE and TXC used in AVR microcontroller communication

Publisher:fengtingLatest update time:2020-02-04 Source: eefocusKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The AVR manual says:


"The TXC flag can be used to check whether the transmission of a data frame has been completed, and the RXC flag can be used to check whether there is any data in the receive buffer that has not been read out. The TXC flag must be cleared before each data transmission (before writing the transmit data register UDR)."


"The data register empty UDRE flag indicates whether the transmit buffer can accept a new data. This bit is set to "1" when the transmit buffer is empty; it is cleared when the transmit buffer contains data to be sent."


"When the entire data frame is shifted out of the transmit shift register and there is no new data in the transmit buffer, the transmit end flag TXC is set. TXC is automatically cleared when the transmission end interrupt is executed, and can also be cleared by writing "1" to this bit."


After reading the above instructions, I have been wondering whether I need to perform two operations at the same time when sending data:


1. Determine that UDRE is 1.


2. Clear the TXC mark.


However, the utilities I saw online did not have the second operation above, which seemed to work. With this doubt, I searched online and found a better answer:


"Regarding the AVR serial port, the explanation is as follows:


For transmission, there is a UDR buffer register and a shift register. When you write a UDR, the microcontroller immediately transfers the data to the shift register, so you can write the second data immediately. In the future, whenever the UDR buffer register is empty, a UDRE interrupt will be generated. To generate a TXC interrupt, you must wait until the data in the shift register has been sent.


For receiving, there are two UDR buffer registers and one shift register. The two receive buffers are equivalent to a FIFO structure. When there is data to be received, if a complete data is received into the shift register, it will be transferred to the buffer register. This will generate an RXC interrupt.


AVR is different from 51, so this structure is better. For example, when your program is busy in another interrupt, the serial port receives data. The two buffers will buy you time and will not lose data. The same is true for sending data. This is not the case with 51. "


"If you write two buffer data continuously, because the data just written to the buffer has been shifted to the shift register, you can write another data immediately. That is to say, when UDRE is set, the microcontroller still has a byte in the shift register being sent."


The conclusion is:


The common cyclic transmission program (i.e., the transmission program that only judges UDRE but not TXC) can work. The reason is the continuity of the transmitted data: that is, TXC=0 at the beginning, which meets the transmission conditions; when the data is continuously transmitted, because UDRE is set, there is still data in the shift register to be transmitted, so TXC is not set, which also meets the transmission conditions. TXC is not set until all data are sent and there is no data in the shift register and the transmission buffer.


have to be aware of is:


1. If a round of data has been sent before, the TXC flag must be cleared when sending again, that is, write "1" to this bit. It is best to detect the TXC flag and clear it after a round of data is sent.


2. If the transmit completion interrupt is used, there is no need to clear it manually, because after entering the transmit interrupt program, the hardware can automatically clear the TXC flag.


3. If interrupt transmission is not used but cyclic transmission is adopted, if the transmission program is suspended for more than a certain time due to other interrupts during the transmission process, the TXC flag bit will be set after the data in the shift register is sent, and subsequent transmission will be impossible.


4. If 485 is used for communication, the state of 485 will be changed only when TXC is detected to be set. Because only when TXC is set, it means that the sending process is completed.


I think the better sending procedure is as follows:


void uart_putchar(unsigned char c)


{


while(!(UCSR0A&(1<


if(UCSR0A&(1<


UCSR0A|=(1<


UDR0 = c;


}


Keywords:AVR Reference address:The difference between the sending identifier UDRE and TXC used in AVR microcontroller communication

Previous article:AVR microcontroller and its features
Next article:Design of RTU Radio Telemetry System Based on AVR Microcontroller

Recommended ReadingLatest update time:2024-11-16 11:46

AVR USART serial port program
About usart: The Universal Synchronous and Asynchronous Serial Receiver and Transmitter (USART) is a highly flexible serial communication device. The main features are: Full-duplex operation (independent serial receive and transmit registers) Asynchronous or synchronous operation Synchronous operation with clock
[Microcontroller]
Five working types of AVR microcontroller timer
5 types of work Normal mode WGM1 = 0 is similar to the normal mode of 51, with TOV1 overflow interrupt flag, which occurs when MAX (0xFFFF) 1. Use the internal counting clock for ICP capture input occasions - measuring pulse width/infrared decoding (the capture input function can work in multiple modes, not just the
[Microcontroller]
Five working types of AVR microcontroller timer
AVR MCU timer, PWM, ICP examples
/*********************************************** **** AVR Timer Usage Examples *** ****                                              *** **** Compiler: WINAVR20050214 *** ***********************************************/ /* This program simply demonstrates how to use the ATMEGA16 timer AVR timer key point
[Microcontroller]
AVR MCU driver CH451 example program_C language
1) Introduction to CH451 CH451 can be used in the fields of LED digital tube display drive, keyboard scan control, μP monitoring circuit, etc. The chip package includes dual in-line DIP28, SOP28 and DIP24S package. It has a built-in RC oscillator circuit, which can directly and dynamically drive 8-bit digital tubes
[Microcontroller]
AVR MCU driver CH451 example program_C language
AVR USART (UART) send interrupt program using buffer
System functions    Use AVR's USART for self-transmission and self-reception (short-connect the transmit pin RXD to the receive pin TXD), send data: 0, 1, 2... data, and receive the data you send: 0, 1, 2... Use LED to make simple instructions!   hardware design
[Microcontroller]
AVR USART (UART) send interrupt program using buffer
Creating project files based on AVR Studio5.1
After opening the software, find New Project (left click) The following dialog box appears   Select according to the mark in the figure, change the name and path by yourself, and click OK after the settings are completed. Enter the MCU selection dialog box and find the MCU model you are using.   Click OK This
[Microcontroller]
Creating project files based on AVR Studio5.1
AVR fixed-point arithmetic programming and number system conversion
AVR microcontrollers have addition and subtraction instructions, and you can directly call related instructions to achieve your goals. Here are listed 16-bit addition, 16-bit addition with immediate value, 16-bit subtraction, 16-bit subtraction with immediate value, 16-bit compare, 16-bit compare with immediate value
[Microcontroller]
AVR Mega16 PAL/NTSC B/W signal simulation
References http://www.rickard.gunee.com/projects/video/pic/howto.php http://tinyvga.com/avr-sdram-vga http://www.serasidis.gr/circuits/colour_bar_gen/colour_bar_gen.htm http://belogic.com/uzebox/index.asp The following is quoted from http://eyetap.org/ece385/lab5.htm SEQUENCE: Horizontal sync (hsync) pu
[Microcontroller]
AVR Mega16 PAL/NTSC B/W signal simulation
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号