初中生
最后登录1970-1-1
在线时间 小时
注册时间2018-8-21
|
本帖最后由 litianma 于 2018-10-5 18:09 编辑
初学者,折腾了两天终于搞定了怎么使用串口接收不定长字符串。中断程序程序如下:void DEBUG_USART_IRQHandler(void)
{
if(USART_GetITStatus(DEBUG_USARTx, USART_IT_RXNE) != RESET)
{
/* Read one byte from the receive data register */
/* Disable the USARTy Receive interrupt */
//USART_ITConfig(DEBUG_USARTx, USART_IT_RXNE, DISABLE);
RxBuffer1[RxCounter1++] = USART_ReceiveData(DEBUG_USARTx);
//printf("RxCounter1= %d",RxCounter1);
//LED_RED;
}
else if(USART_GetFlagStatus(DEBUG_USARTx,USART_FLAG_IDLE) != RESET)
{
//USART_ITConfig(DEBUG_USARTx, USART_IT_RXNE, DISABLE);
USART_ReceiveData(DEBUG_USARTx); //读SR寄存器
USART_ClearFlag(DEBUG_USARTx,USART_FLAG_IDLE); //读DR寄存器(先读SR再度DR,可以清除IDLE中断)
LED3_ON;
flag=1;
printf("Flag= %d,RxCounter1= %d",flag,RxCounter1);
}
if(flag)
{
printf("数据是:%s",RxBuffer1);
flag=0;
RxCounter1=0;
memset(RxBuffer1, 0, sizeof RxBuffer1);
}
}
实验结果:
|
|