uart send add timeout
authorkyz <kyz@kyz.pub>
Tue, 1 Mar 2022 07:51:46 +0000 (15:51 +0800)
committerkyz <kyz@kyz.pub>
Tue, 1 Mar 2022 07:51:46 +0000 (15:51 +0800)
Core/Src/user_rs485.c

index 3d79175d84a644e15bd7d0e9f4eb527dbb4c48dc..66f13c6c9c649099ad7a07f3b67afa8175ca1b1c 100644 (file)
@@ -38,10 +38,12 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
 
 int32_t UART2_Send( uint8_t *data, uint16_t data_size )
 {
-       
-  while (Uart2Ready != SET)
-  {
-  }
+       uint32_t tick;
+       tick = HAL_GetTick() + 1000;  
+       while (Uart2Ready != SET){
+               if( tick < HAL_GetTick() )
+                       break;
+       }
   
        Uart2Ready = RESET;
        RS485_RTS1_TX();
@@ -63,11 +65,14 @@ int32_t UART2_Send( uint8_t *data, uint16_t data_size )
 
 int32_t UART1_Send( uint8_t *data, uint16_t data_size )
 {
-
-       while (Uart1Ready != SET)
+       uint32_t tick;
+       tick = HAL_GetTick() + 1000;  
+       while (Uart2Ready != SET)
        {
+               if( tick < HAL_GetTick() )
+                       break;
        }
-       
+
        Uart1Ready = RESET;
        if (HAL_UART_Transmit_IT(&huart1, data, data_size) != HAL_OK)
   {
@@ -117,6 +122,7 @@ void UART2_Recv_Restart( void )
        memset(rx_buffer, 0, sizeof(rx_buffer));
        rx_count=0;
        UART2_Recv_Start();
+       Uart2Ready = SET;
 }
 
 int32_t        get_rx_buffer( uint8_t **rx_buf, uint16_t *rx_cnt )