stm32f070做串口中断接收数据,连续快速接收数据的时候总是死机,有没有大神遇到过这个问题啊?
void USART2_IRQHandler(void) //′®¿ú1ÖD¶Ï·tÎñ3ìDò
{
uint8_t Res;
if(USART_GetFlagStatus(USART2,USART_FLAG_ORE)!=RESET)
{
USART_ClearFlag(USART2,USART_FLAG_ORE);
USART_ReceiveData(USART2);
}
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //½óêÕÖD¶Ï(½óêÕμ½μÄêy¾Y±ØDëêÇ0x0d 0x0a½áÎ2)
{
Res =USART_ReceiveData(USART2); //¶á衽óêÕμ½μÄêy¾Y
if((USART_RX_STA&0x8000)==0)//½óêÕÎ′íê3é
{
if(USART_RX_STA&0x4000)//½óêÕμ½áË0x0d
{
if(Res!=0x0a)USART_RX_STA=0;//½óêÕ′íÎó,ÖØD¿aê¼
else USART_RX_STA|=0x8000; //½óêÕíê3éáË
}
else //»1ûêÕμ½0X0D
{
if(Res==0x0d)USART_RX_STA|=0x4000;
else
{
USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
USART_RX_STA++;
if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//½óêÕêy¾Y′íÎó,ÖØD¿aê¼½óêÕ
}
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一开始我也以为是USART_IT_RXNE标志位未清除,所以加了USART_ClearITPendingBit(USART2,USART_IT_RXNE);这句,还是没有解决
void USART2_Init(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
USART_DeInit(USART2);//¸′λ′®¿ú1
USART_InitStructure.USART_BaudRate = 115200;//′®¿ú2¨ìØÂêÎa115200
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö3¤Îa8λêy¾Y¸ñê½
USART_InitStructure.USART_StopBits = USART_StopBits_1;//ò»¸öí£Ö1λ
USART_InitStructure.USART_Parity = USART_Parity_No;//ÎTÆæżD£Ñéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎTó2¼têy¾Yá÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//êÕ·¢Ä£ê½
USART_Init(USART2, &USART_InitStructure); /* USART configuration */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1); /* Connect PXx to USARTx_Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1); /* Connect PXx to USARTx_Rx */
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;//Ö¸¶¨ÅäÖÃμÄIO¿úζA9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//Ä£ê½Îa¸′óÃÄ£ê½
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;//1¤×÷ÆμÂêÎa10MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//êä3öààDíÎaíÆíìêä3ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//éÏà-
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART2 NVIC ÅäÖÃ
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority=1 ;//óÅÏ輶1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);////¿aÆô′®¿ú½óêüÖD¶Ï
/* Enable USART */
USART_Cmd(USART2, ENABLE);
}
一周热门 更多>