question
When I was working on a project, I found that the program would die inexplicably, because the serial port communication was used, and the data needed to be received continuously, and the frequency was relatively fast.
Using JLink for hardware debugging, I found that it was dead in the serial port interrupt, and kept entering the interrupt. I checked the register status and found that the ORE control bit was enabled . After checking the data, I found that the problem was caused by the detection of an overflow error .
When the ore interrupt occurs, you cannot go through the watch window. You must wait until it appears before reading the SR register. Otherwise, if you keep reading in the window, the interrupt will never reappear because it is cleared. Read the manual.
You can't use this window to observe, otherwise it will still quack, this problem is really scratching your head
reason
When receiving data, if RXNE has not been reset, an overflow error will occur if another character is received at this time. For example, if I interrupt the point above, the serial port assistant will send data continuously, and it will be fine.
solve
if(USART_GetFlagStatus(USART1, USART_FLAG_ORE) != RESET)
{
res_err=USART_ReceiveData(USART1);
//USART_ClearFlag(USART1, USART_FLAG_ORE); //清除溢出中断,其实没用,因为手册里讲了
//通过读入USART_SR 寄存器,然后读入 USART_DR寄存器来清除标志位
}
//USART_ClearFlag(USART1, USART_FLAG_ORE); //Clear the overflow interrupt, it is useless, because it is mentioned in the manual
// By reading into the USART_SR register, and then reading into the USART_DR register to clear the flag bit
So it's useless to do the following
if(USART_GetFlagStatus(USART2, USART_FLAG_ORE) != RESET)
{
USART_ClearFlag(USART2, USART_FLAG_ORE); //清除溢出中断
}
The function also explains it, please don’t make something out of nothing, take it for granted
Replenish
Some people say that the following sentence can enable ORE interrupt, and ore is automatically enabled when RXNE is turned on, so this sentence is useless
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
//USART_ITConfig(USART1,USART_IT_ORE,ENABLE);//有的说这样能打开ORE中断,ore是在打开RXNE自动开启的,所以这句话没吊用
You see, they don't have this parameter at all.
Parameter checks also don't pass
assert_param(IS_USART_CONFIG_IT(USART_IT));
#define IS_USART_CONFIG_IT(IT) (((IT) == USART_IT_PE) || ((IT) == USART_IT_TXE) || \
((IT) == USART_IT_TC) || ((IT) == USART_IT_RXNE) || \
((IT) == USART_IT_IDLE) || ((IT) == USART_IT_LBD) || \
((IT) == USART_IT_CTS) || ((IT) == USART_IT_ERR))
Reference Article:
Article
Summarize
Don't take it for granted
, read more manuals, the English version is the most official, and the Chinese translation is wrong
Reprint without statement, Tan Ni is in a hurry