Cannot transmit every characters through UART

狂风中的少年 提交于 2019-11-28 12:34:41

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

You should make a tx array buffer as well, and use interrupt for writing as well (The first write if not enabled yet, should be sent immediately).

There should be examples of this for STM32 around.

You should probably switch the two lines: Transmit and Receive. The Transmit function waits for a timeout to send the character, in meantime the next received character is missed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!