STM8 串口接收字符串问题

来源:互联网 发布:雄霸九州辅助软件 编辑:程序博客网 时间:2024/06/06 15:35

此处附上接收中断源码

#ifdef _RAISONANCE_void USART_RX_IRQHandler(void) interrupt 28#endifuint8_t cnt_USART ;#ifdef _IAR_SYSTEMS_#pragma vector=30__interrupt void USART_RX_IRQHandler(void)#endif{    /* In order to detect unexpected events during development,   it is recommended to set a breakpoint on the following instruction.    */    USART_ClearITPendingBit ();//清中断标志    if(!USART_GetFlagStatus (USART_FLAG_RXNE))//等待接收完毕    {          p_rxbuf[cnt_USART++] = USART_ReceiveData8();     //接收数据       if(cnt_USART == 0x0B)        cnt_USART = 0xFF ;    }//    USART_RendCmd(p_rxbuf);  //接收11bytes串口指令}
cnt_USART 为全局变量,因为每次接收每次只是接收1byte,因此,在主程序应该进行适当的延时来等待缓冲区的数据被读取。

       while(cnt_USART!=0xFF)       {        if(mark_1ms >100)          break;       }
在函数进行适当的延时进行等待,mark_1ms 此处是使用TIM2进行延时,也可以在主函数中进行空函数延时。



原创粉丝点击