linux 串口 断帧,STM32f103使用串口中断发送数据时出现断帧是什么原因?

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 );

}

}

699ba7046c51816a17b33a7caa85f179.png

0

97b4b3417991aabde46fdac613e34292.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值