打印
[STM32F1]

STM32f103使用Ucosii 串口中断发送数据出现断帧问题

[复制链接]
1495|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
suqiang1271|  楼主 | 2018-10-16 14:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在使用STM32f103做一个项目,使用串口中断发送数据时,数据出现了断帧,断帧的间隔时间从串口打印log来看,最大的达到40多ms,小的时间间隔也有20ms左右,不知道是不是因为操作系统造成了。
1.系统是用的ucos ii
2.串口使用了串口1 和 2 都是利用串口中断接收和发送
3.部分驱动代码
谢谢各位
/*=======================================================================================================
*Function:  Bsp_UartNVIC_Config( ) =>
*Input   :  *Uart
*Output  :  None
========================================================================================================*/
void Bsp_UartNVIC_Config( UART_Def *Uart  )
{
    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_InitStructure.NVIC_IRQChannel = Uart->UARTx_IRQn;                      //Enable the USARTy Interrupt
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = Uart->PreemPriority;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = Uart->SubPriority;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}
/*=======================================================================================================
*Function:  Bsp_UartConfig( ) =>
*Input   :  *Uart
*Output  :  None
========================================================================================================*/
void Bsp_UartConfig( UART_Def *Uart )
{
    USART_InitTypeDef USART_InitStructure1;
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd( Uart->RCC_PinPort, ENABLE );                        // config USARTx Pin clock
     
    if( Uart->USARTx == USART2 || Uart->USARTx == USART3 )                      // config USARTx clock
    {
      RCC_APB1PeriphClockCmd( Uart->RCC_Uartx, ENABLE );
    }
    else if( Uart->USARTx == USART1 )                                          // config USARTx clock
    {
      RCC_APB2PeriphClockCmd( Uart->RCC_Uartx, ENABLE );
    }

    GPIO_InitStructure.GPIO_Pin = Uart->Rx_Pinx;                                // Configure USARTy Rx as input floating
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init( Uart->PinPort, &GPIO_InitStructure );
   
    GPIO_InitStructure.GPIO_Pin = Uart->Tx_Pinx;                                //Configure USARTy Tx as alternate function push-pull
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
    GPIO_Init( Uart->PinPort, &GPIO_InitStructure );
   
    USART_InitStructure1.USART_BaudRate = Baud_Table[ Uart->Baud_Rate ];        //USART1 mode config
    USART_InitStructure1.USART_WordLength = USART_WordLength_8b;
    USART_InitStructure1.USART_StopBits = USART_StopBits_1;
    USART_InitStructure1.USART_Parity = Parity_Table[ Uart->Parity ] ;
    USART_InitStructure1.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_InitStructure1.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
    USART_Init( Uart->USARTx, &USART_InitStructure1 );

    USART_ITConfig( Uart->USARTx, USART_IT_RXNE , ENABLE );
    USART_ITConfig( Uart->USARTx, USART_IT_IDLE , ENABLE );
    USART_ITConfig( Uart->USARTx, USART_IT_TXE , DISABLE );   
   
    USART_Cmd( Uart->USARTx, ENABLE );
   
}
/*=======================================================================================================
*Function:  Bsp_UartRingSend( ) => USARTx send data from ring buff
*Input   :  *Uart, data
*Output  :  None
========================================================================================================*/
void Bsp_UartIntRingSend( UART_Def *Uart )
{
    uint8_t data;
      
    if( Get_bytes_count( &Uart->T_RingBuff ) != 0 )
    {
#if RS485_EN_USE == true
      RS485_TX_EN();
#endif
      
      Read_ring_buffer( &Uart->T_RingBuff, &data, 1 );
      Bsp_UartSendData( Uart, data );
      
      if( Uart->TxBusy == false )
      {
        Uart->TxBusy = true;
        USART_ITConfig( Uart->USARTx, USART_IT_TXE , ENABLE );
      }
    }
    else
    {
#if RS485_EN_USE == true      
      g_Time3Count.rxdelay = RS485_RxDelayTable[ Uart->Baud_Rate ];        
#endif
      Uart->TxBusy = false;
      USART_ITConfig( Uart->USARTx, USART_IT_TXE , DISABLE );
    }
}
沙发
643757107| | 2018-10-16 16:51 | 只看该作者
被更高等级的中断拦截了。

使用特权

评论回复
板凳
df_flying| | 2018-10-16 16:54 | 只看该作者
加个互斥信号量就可以了

使用特权

评论回复
地板
稳稳の幸福| | 2018-10-16 19:52 | 只看该作者
系统是不是有其他更高优先级的中断发送。

使用特权

评论回复
5
huangcunxiake| | 2018-10-16 21:35 | 只看该作者
没有用过103跑系统的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

12

主题

44

帖子

1

粉丝