USART_GetITStatus函数里面没有DR寄存器的操作嘛, 这是库函数的代码 //-------------------------------------------------------------------------------------------------- // USART_GetITStatus //-------------------------------------------------------------------------------------------------- //! rief Checks whether the specified USART interrupt has occurred or not. //! //! param[in] - USARTx: Select the USART or the UART peripheral. //! This parameter can be one of the following values: //! - USART1, USART2, USART3, UART4 or UART5. //! //! param[in] - USART_IT: specifies the USART interrupt source to check. //! This parameter can be one of the following values: //! - USART_IT_CTS: CTS change interrupt (not available for //! UART4 and UART5) //! - USART_IT_LBD: LIN Break detection interrupt //! - USART_IT_TXE: Tansmit Data Register empty interrupt //! - USART_IT_TC: Transmission complete interrupt //! - USART_IT_RXNE: Receive Data register not empty //! interrupt //! - USART_IT_IDLE: Idle line detection interrupt //! - USART_IT_ORE: OverRun Error interrupt //! - USART_IT_NE: Noise Error interrupt //! - USART_IT_FE: Framing Error interrupt //! - USART_IT_PE: Parity Error interrupt //! //!
eturn None //-------------------------------------------------------------------------------------------------- ITStatus USART_GetITStatus(USART_TypeDef* USARTx, INT16U USART_IT) { INT32U bitpos = 0x00, itmask = 0x00, usartreg = 0x00; ITStatus bitstatus = RESET;
// Check the parameters ASSERT(IS_USART_ALL_PERIPH(USARTx)); ASSERT(IS_USART_GET_IT(USART_IT)); ASSERT(IS_USART_PERIPH_IT(USARTx, USART_IT)); // The CTS interrupt is not available for UART4 and UART5
// Get the USART register index usartreg = (((INT8U)USART_IT) >> 0x05);
// Get the interrupt position itmask = USART_IT & IT_Mask;
itmask = (INT32U)0x01 << itmask;
if (usartreg == 0x01) // The IT is in CR1 register { itmask &= USARTx->CR1; } else if (usartreg == 0x02) // The IT is in CR2 register { itmask &= USARTx->CR2; } else // The IT is in CR3 register { itmask &= USARTx->CR3; }
也就是说我line5整个函数单步,应该是很快就直接走到line6,并且串口助手会收到一组string。 但是事实上不是这样,会等很长一段时间,并且没到line6,因此我停下debug, 发现停在USART_GetITStatus 函数,这个函数是中断才调用的,也就是说我进入了中断。并且我发现ORE bit 为1,当我出中断函数的时候,ORE bit = 0; 但是随后会反复进入中断,不知道为什么。
另外,虽然硬件上我tx,rx由于要使用1-wire功能的原因,是短接在一起的,但是我line5发送的过程中,再发送前,我是disable usart2中断的; 当我发送完后, // wait until finish sending data while (USART_GetFlagStatus(log_USART, USART_FLAG_TC) == RESET); 这句执行完,确保数据发送已经完成了,才去打开usart2中断。 并且打开前,我先进行SR的标志位清0,以消除rx线上由于发送string时引起的中断标志位。