经过反复调试,我怀疑问题出在ORE寄存器,但是在串口中断里面加了
if((USART1->ISR)&0x000f != 0)//F100是USART1->SR
USART_ReceiveData(USART1);
F100手册上说
ORE: Overrun error
This bit is set by hardware when the word currently being received in the shift register is
ready to be transferred into the RDR register while RXNE=1. An interrupt is generated if
RXNEIE=1 in the USART_CR1 register. It is cleared by a software sequence (an read to the
USART_SR register followed by a read to the USART_DR register).
0: No Overrun error
1: Overrun error is detected
Note: When this bit is set, the RDR register content will not be lost but the shift register will be
overwritten. An interrupt is generated on ORE flag in case of Multi Buffer
communication if the EIE bit is set.
而F301手册上说
ORE: Overrun error
This bit is set by hardware when the data currently being received in the shift register is
ready to be transferred into the RDR register while RXNE=1. It is cleared by a software,
writing 1 to the ORECF, in the USARTx_ICR register.
An interrupt is generated if RXNEIE=1 or EIE = 1 in the USARTx_CR1 register.
0: No overrun error
1: Overrun error is detected
Note: When this bit is set, the RDR register content is not lost but the shift register is
overwritten. An interrupt is generated if the ORE flag is set during multi buffer
communication if the EIE bit is set.
This bit is permanently forced to 0 (no overrun detection) when the OVRDIS bit is set in
the USARTx_CR3 register.
貌似F301读数据不会清ORE
现在我在F301的代码中让OVRDIS置位,强制ORE为0,然后代码可以正常运行了,暂时没发现异常