Cannot transmit every characters through UART

前端 未结 3 1346
时光说笑
时光说笑 2020-12-11 07:38

I am using stm32f0 MCU.

I would like to transmit every single byte received from the uart out of the uart. I am enabling an interrupt on every byte received from uar

3条回答
  •  醉话见心
    2020-12-11 08:09

    Reenabling interrupts may be inefficient. With a couple of modifications it is possible to keep the interrupt active without needing to write the handler all over again. See the example below altered from the stm32cubemx generator.

    /**
    * @brief This function handles USART3 to USART6 global interrupts.
    */
    void USART3_6_IRQHandler(void)
    {
      InterruptGPS(&huart5);
    }
    
    void InterruptGPS(UART_HandleTypeDef *huart) {
        uint8_t rbyte;
        if (huart->Instance != USART5) {
            return;
        }
        /* UART in mode Receiver ---------------------------------------------------*/
        if((__HAL_UART_GET_IT(huart, UART_IT_RXNE) == RESET) || (__HAL_UART_GET_IT_SOURCE(huart, UART_IT_RXNE) == RESET)) {
            return;
        }
        rbyte = (uint8_t)(huart->Instance->RDR & (uint8_t)0xff);
        __HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST);
    
        // do your stuff
    
    }
    
    static void init_gps() {
        __HAL_UART_ENABLE_IT(&huart5, UART_IT_RXNE);
    }
    

提交回复
热议问题