Skip to main content
Associate II
April 7, 2026
Question

ADC DMA Multiple channel

  • April 7, 2026
  • 2 replies
  • 250 views

Post edited by ST community moderator. In next time please use </> to share a code.

HI, I have Implemented ADC1 - DMA with one channel and ADC2 - DMA with 7 channels and im transmitting data through UART IT. I want to know if this code works usually.

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if (hadc->Instance == ADC1)
Print_ADC_Values_IT();

if (hadc->Instance == hadc2.Instance)
Print_ADC_Values_IT();
}
hadc2 is workin only when i disable 

HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&adc1_value, 1);

Here's the overview of my code:


MX_GPIO_Init();

MX_DMA_Init();

MX_ADC1_Init();

MX_ADC2_Init();

MX_USART1_UART_Init();

/* USER CODE BEGIN 2 */

// HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);

HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED);

// Start ADC1 (1 channel)

// HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&adc1_value, 1);



// Start ADC2 (7 channels)

HAL_ADC_Start_DMA(&hadc2, (uint32_t*)adc2_values, ADC2_CHANNELS);


user code 4

HAL_ADC_ConvCpltCallback

HAL_UART_TxCpltCallback
Print_ADC_Values_IT

 

2 replies

TDK
Super User
April 7, 2026

> I want to know if this code works usually.

Seems like something you could verify yourself, no? All of your ADC1 code is commented out, so that won't work.

You'll need to ensure interrupts are not called too often and that you have sufficient bandwidth for the data you send out over UART. Generally this means slowing down the ADC conversion rate.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate II
April 10, 2026

I have verified them by debugging. I can either see ADC1 or ADC2 in the following function.Initially I had Both ADC1 and ADC2. I have commented one ADC to verify this"HAL_ADC_ConvCpltCallback" functionHAL_ADC_ConvCpltCallback

 Can you please let me help me in finding how often i can use both ADC1 and ADC2 DMA 

TDK
Super User
April 10, 2026

Expect interrupts to be limited to maybe 10k calls per second. Depends on a lot of things. Calling a DMA interrupt after every single sample isn't very efficient. You're probably converting at the max speed and the cpu can't keep up. The relevant code for this is not shown.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Karl Yamashita
Principal
April 8, 2026

You want to avoid printing from an interrupt, else that will cause blocking code and prevent other interrupts from firing in a timely matter.

Instead, copy the ADC data to a buffer, set a ready flag and exit the callback. Then in your main while loop, check for the flag(s) and print the ADC values.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Associate II
April 10, 2026

Sure, Thank you for the suggestion. I will definitely try this solution