emmmmm,虽然说STM32的东西很基本很基本了但是如果不做点记录的话好多坑都会忘记,所以还是弄个踩坑记录吧。
USART的中断类型除了RXNE/TXE之外还有一个经常用到的是IDLE,但是st的官方库函数在中断处理函数中处理IDLE时有个bug:进IDLE后,必须要读取SR,DR寄存器后再执行功能代码,不然会一直进IRQHandler(死循环)。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
extern "C"
{
void USART2_IRQHandler()
{
uint8_t tsr;
uint8_t tdr;
if(USART_GetITStatus(USART2,USART_IT_IDLE)==SET)
{
tsr=USART2->SR;
tdr=USART2->DR;
//TODO:Meow
USART_ClearFlag(USART2,USART_IT_IDLE);
}
}
}
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.