lingjianer 发表于 2011-5-12 21:59:07

使用mega16的USART轮询UDRE发送数据时需要在写入UDR后人工清零吗

请问马老师如题问题,在您的书上的例程里都没有对UDRE进行人工清零,可是我在AVRstudio中调试时发现UDRE并不在往UDR中写入数据后自动清零呢。所以对这个问题有些疑惑,盼您解答~

lingjianer 发表于 2011-5-12 22:13:58

另外,马老师,我还注意到,当向RXC/TXC中写入1时不但将对应位清零了,同时还将UDRE位同时清零了,是这样的吗?而单独向UDRE中写入1时并不能将之清零

machao 发表于 2011-5-13 11:05:26

书只是作为一个学习和应用的指导,真正的理解还需要仔细的阅读器件手册。下面我把手册中相关的部分贴上,你先看看,是否能理解?

===========================================
Transmitter Flags and Interrupts

The USART transmitter has two flags that indicate its state: USART Data Register Empty (UDRE) and Transmit Complete (TXC). Both flags can be used for generating interrupts.

The Data Register Empty (UDRE) Flag indicates whether the transmit buffer is ready to receive new data. This bit is set when the transmit buffer is empty, and cleared when the transmit buffer contains data to be transmitted that has not yet been moved into the Shift Register. For compatibility with future devices, always write this bit to zero when writing the UCSRA Register.

When the Data Register empty Interrupt Enable (UDRIE) bit in UCSRB is written to one, the USART Data Register Empty Interrupt will be executed as long as UDRE is set (pro-vided that global interrupts are enabled). <a href=>UDRE is cleared by writing UDR</a>. When interrupt-driven data transmission is used, the Data Register Empty Interrupt routine must either write new data to UDR in order to clear UDRE or disable the Data Register empty Interrupt, otherwise a new interrupt will occur once the interrupt routine terminates.

==================================================
• Bit 5 – UDRE: USART Data Register Empty
The UDRE Flag indicates if the transmit buffer (UDR) is ready to receive new data. If UDRE is one, the buffer is empty, and therefore ready to be written. The UDRE Flag can generate a Data Register empty Interrupt (see description of the UDRIE bit).

UDRE is set after a reset to indicate that the transmitter is ready.

michael_chu 发表于 2013-10-18 16:31:59

我的理解:
1.UDRE只是一个“标志位”,它属于read-only型;
2.cpu复位后,以及大部分时间, UDRE状态都是1;只有当执行“给UDR写数据”的时候状态是0, 但是这个语句执行完后(由于UART启动后会自动发送数据)UDR的状态又变成1;
3.UDRE 的状态是1还是0,都没有关系,它作用是“中断标示”和“显示UDR的状态”
页: [1]
查看完整版本: 使用mega16的USART轮询UDRE发送数据时需要在写入UDR后人工清零吗