Electronic – STM32 HAL Using ADC with DMA affects UART transmission

adcdmastm32uart

I am using STM32 Nucleo F334R8 board. I transmit some data using UART in asynchronous mode to my PC using:

HAL_UART_Transmit_IT(&huart2, &data, sizeof(data));

I noticed that after enabling ADC in DMA mode microcontroller started to send incorrect data over UART.

When I just only commented out:

HAL_ADC_Start_DMA(&hadc1, adc_dma_values, 2);

UART transmission sends correct data.

When I replaced HAL_UART_Transmit_IT() with HAL_UART_Transmit() it also surprisingly works well.

I do not understand how HAL_ADC_Start_DMA() may affect HAL_UART_Transmit_IT().

Here's whole code of main.c, maybe it would be helpful.

Best Answer

Based on the followings:

  • the UART is working if you are using it without interrupts along with the DMA, and

  • if DMA is not used the UART works with interrupts.

The DMA interrupts possibly happens so often that it do not let the UART IRQ to be executed as the CPU is always busy to handle DMA interrupts.

Giving higher priority to UART IRQ should solve the issue.