简体   繁体   中英

STM32 HAL rx interrupt can't get bytes correctly

Hi guys I am trying to make serial rx interrupt using stm32 HAL library and I got error what I dont know.

It is really simple program. PC gives bytes to stm32 board and stm32 will take those bytes using rx interrupt routine.

Problem is when i send over 4 bytes ,such as "12345", stm32 board only got 4 bytes and last one byte(5) is gone somewhere. Here is picture for better understanding.

在此输入图像描述

Here is my code in HAL_UART_RxCpltCallback routine:

HAL_UART_Transmit(&huart4, &receive1, 1, 1000);
HAL_UART_Receive_IT(&huart4, &receive1, 1);

If you have any idea, please comment :)

check the function: HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size) ;

  1. make a size enough longer like 16bytes for example;
  2. call your HAL_UART_RxCpltCallback routine into the function HAL_UART_Receive_IT(...) . I suggest to you to add an end character ( \\n ) detection like this:

     if ( (*huart->pRxBuffPtr) == '\\n') { HAL_UART_RxCpltCallback(huart); //-------------------------------------------///////// } else { huart->pRxBuffPtr++; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM