问题
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 :)
回答1:
check the function: HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
;
- make a size enough longer like 16bytes for example;
call your
HAL_UART_RxCpltCallback
routine into the functionHAL_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++; }
来源:https://stackoverflow.com/questions/37829430/stm32-hal-rx-interrupt-cant-get-bytes-correctly