HAL_UART_Receive_IT( &huart2, (uint8_t * )aRXBufferUser, RX_BUFFER_SIZE); ... void HAL_UART_RxCpltCallback(UART_HandleTypeDef * huart) { /* USER CODE BEGIN HAL_UART_RxCpltCallback_1 */ /* USER CODE END HAL_UART_RxCpltCallback_1 */ if (huart->Instance == USART1) { if ((NULL != RxCpltCallback) && (HAL_UART_ERROR_NONE == huart->ErrorCode)) { RxCpltCallback( &charRx, 1, 0); } HAL_UART_Receive_IT(huart, &charRx, 1); } /* USER CODE BEGIN HAL_UART_RxCpltCallback_2 */ if (huart->Instance == USART2) { UART2_SET = 1; } /* USER CODE END HAL_UART_RxCpltCallback_2 */ } void MeasurePM_sens(void) { uint16_t RxLen; if (aRXBufferUser[0] == 0x02 && aRXBufferUser[31] == 0x03) { PM2_5 = aRXBufferUser[5] + aRXBufferUser[6] * 256 + aRXBufferUser[7] * 65536; UART2_SET = 0; HAL_UART_Receive_IT( &huart2, (uint8_t * )aRXBufferUser, RX_BUFFER_SIZE); } else HAL_UARTEx_ReceiveToIdle( &huart2, (uint8_t * )aRXBufferUser, RX_BUFFER_SIZE, &RxLen, 1000); }//or:
HAL_UARTEx_ReceiveToIdle_IT(&huart2, (uint8_t*) aRXBufferUser, RX_BUFFER_SIZE);
Ok it not fixed fully will add some timer... probably..upd: interesting but works - two calls together:
HAL_UART_Receive_IT(&huart2, (uint8_t *) aRXBufferUser, RX_BUFFER_SIZE); HAL_UARTEx_ReceiveToIdle(&huart2, (uint8_t *) aRXBufferUser, RX_BUFFER_SIZE, &RxLen, 1000);