STM8S105K6使用串口中断发送,如何清发送完成中断TXE?找了一个例程
INTERRUPT_HANDLER(UART2_TX_IRQHandler, 20){ // 写操作自动清中断,因此可以不用显式清中断
UART2_ClearITPendingBit(UART2_IT_TXE);
// 从写缓冲中写出1字节 UART2_SendData8(writ_buffer[writ_idx++]);
// 全部写完、关写中断、置写完成标志(同步化处理)
if( writ_idx == writ_len ) { UART2_ITConfig(UART2_IT_TXE, DISABLE); writ_ok = 1; }
}
----------------------------------------------------------------------------------------------------------------------------------
这个例程使用UART2_ClearITPendingBit(UART2_IT_TXE); 来清发送完成中断,会导致进入断言while(1)循环void assert_failed(u8* file, u32 line)
查看UART2_ClearITPendingBit函数说明,发现该函数不能请TXE和TC中断,给出的解决方案是UART2_SendData8() or UART2_SendData9(),写数据的方式。单带来的问题是,实际发送数据时,我的最后一个字节发送完了怎么办,没发清中断标志,又无数可发??
----------------------------------------------------------------------------------------------------------------------------------
/**
* @brief Clears the UART2 pending flags.
* @param UART2_IT specifies the pending bit to clear
* This parameter can be one of the following values:
* - UART2_IT_LBDF: LIN Break detection interrupt
* - UART2_IT_LHDF: LIN Header detection interrupt
* - UART2_IT_RXNE: Receive Data register not empty interrupt.
* @note
* - PE (Parity error), FE (Framing error), NE (Noise error),
* OR (OverRun error) and IDLE (Idle line detected) pending bits are
* cleared by software sequence: a read operation to UART2_SR register
* (UART2_GetITStatus()) followed by a read operation to UART2_DR register
* (UART2_ReceiveData8() or UART2_ReceiveData9()).
*
* - RXNE pending bit can be also cleared by a read to the UART2_DR
* register (UART2_ReceiveData8() or UART2_ReceiveData9()).
*
* - TC (Transmit complete) pending bit can be cleared by software
* sequence: a read operation to UART2_SR register
* (UART2_GetITStatus()) followed by a write operation to UART2_DR
* register (UART2_SendData8()or UART2_SendData9()).
*
* - TXE pending bit is cleared only by a write to the UART2_DR register
* (UART2_SendData8() or UART2_SendData9()).
* @retval None
*/
void UART2_ClearITPendingBit(UART2_IT_TypeDef UART2_IT)
|