USART_ClearITPendingBit( UART4, USART_IT_IDLE);
这个用法是错误的!
/**
* [url=home.php?mod=space&uid=159083]@brief[/url] Clears the USARTx's interrupt pending bits.
* @param USARTx: Select the USART or the UART peripheral.
* This parameter can be one of the following values:
* USART1, USART2, USART3, UART4 or UART5.
* @param USART_IT: specifies the interrupt pending bit to clear.
* This parameter can be one of the following values:
* [url=home.php?mod=space&uid=1238002]@arg[/url] USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
* @arg USART_IT_LBD: LIN Break detection interrupt
* @arg USART_IT_TC: Transmission complete interrupt.
* @arg USART_IT_RXNE: Receive Data register not empty interrupt.
*
* @note
* - PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
* error) and IDLE (Idle line detected) pending bits are cleared by
* software sequence: a read operation to USART_SR register
* (USART_GetITStatus()) followed by a read operation to USART_DR register
* (USART_ReceiveData()).
* - RXNE pending bit can be also cleared by a read to the USART_DR register
* (USART_ReceiveData()).
* - TC pending bit can be also cleared by software sequence: a read
* operation to USART_SR register (USART_GetITStatus()) followed by a write
* operation to USART_DR register (USART_SendData()).
* - TXE pending bit is cleared only by a write to the USART_DR register
* (USART_SendData()).
* @retval None
*/
void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT)
从一下的库函数注释来开,这个函数可供清除的中断源 只有
USART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
USART_IT_LBD: LIN Break detection interrupt
USART_IT_TC: Transmission complete interrupt.
USART_IT_RXNE: Receive Data register not empty interrupt.
而清除PE、FE、NE、ORE、IDLE需要读取 SR 与 DR寄存器
以下为正确的串口中断处理
void UART4_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(UART4,USART_IT_RXNE))
{
res = USART_ReceiveData(UART4);
uart4Buff[uart4rs++] = res;
if(uart4rs >= sizeof(uart4Buff))
uart4rs = 0;
}
else if(USART_GetITStatus(UART4, USART_IT_IDLE))
{
res = UART4->SR;
res = UART4->DR;
}
}
积累错误...
|