Question
Hey guys, im new to st and im having hard time with receiving data VIA uart. im trying to receive data with unknown length, decided that the best thing for my application would be idle line interrupt.
my problem is that the DMA only writes to the first address of the buffer,
means that when i look on the buffer, the last byte of the message is stored in the first place of the array, and the rest of the data is overwritten.
what could be the problem, what am i missing?
/* USER CODE BEGIN 2 */
__HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE); // enable idle line interrupt
HAL_UART_Receive_DMA(&huart2, rxBuf, 255);
//__HAL_DMA_ENABLE_IT (&hdma_usart2_rx, DMA_IT_TC);
/* USER CODE END 2 *//**
* @brief This function handles USART2 global interrupt.
*/
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQn 0 */
/* USER CODE END USART2_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART2_IRQn 1 */
if(RESET != __HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE)) //Judging whether it is idle interruption
{
__HAL_UART_CLEAR_IDLEFLAG(&huart2); //Clear idle interrupt sign (otherwise it will continue to enter interrupt)
printf("UART2 Idle IQR Detected\r\n");
HAL_UART_DMAStop(&huart2);
//__HAL_DMA_DISABLE (&hdma_usart2_rx);
uint8_t data_length = 255 - __HAL_DMA_GET_COUNTER(&hdma_usart2_rx);
printf("Receive Data(length = %d): ",data_length);
HAL_UART_Transmit(&huart2,rxBuf,data_length,0x200);
printf("\r\n");
//memset(receive_buff,0,data_length);
HAL_UART_Receive_DMA(&huart2, rxBuf, 255);
}
/* USER CODE END USART2_IRQn 1 */