cancel
Showing results for 
Search instead for 
Did you mean: 

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.

DSosk.1
Associate II

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 */

4 REPLIES 4

The HAL_UART_IRQHandler() will call your call-back routines.

You should definitely avoid blocking HAL_UART_Transmit() function and printf() in the IRQ Handler or call-back routines.

There are significantly cleaner and more efficient approaches to IRQ/DMA than those used by the HAL implementation

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi. Have you configure DMA with destination address increment by byte?

yup

0690X00000Bvu5PQAR.png

New to ST, start simpler, get it working with IRQ, the thing interrupts with every byte, for variable sized packets use a state machine to determine size and packetize to processing task. Assuming someone thought out the protocols so it doesn't need inter-message gaps to demux. ​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..