2026-04-07 12:13 AM - last edited on 2026-04-07 6:30 AM by mƎALLEm
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
2026-04-07 6:26 AM
> 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.
2026-04-08 2:36 PM
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.
2026-04-09 8:58 PM
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
2026-04-09 8:59 PM
Sure, Thank you for the suggestion. I will definitely try this solution
2026-04-09 9:38 PM
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.
2026-04-10 12:16 AM
I am working on a project where I am using 2 ADC IT with overall 8 channels and UART interrupt. There we have had some conflict which is affecting the process. So, we thought of implementing ADC DMA for ADC1 and ADC2. This is what we have developed initially for ADC DMA. Keeping this in mind i just want to know the following things:
1. Can we measure the frequency of interrupt let us say for one channel in ADC for IT and DMA.
2. Is there any other way to get ADC IT frequently.
Thank you for your Time and patience.
2026-04-10 6:35 AM
The conversion rate of the ADC depends on your clock and your sampling period. That dictates how often the interrupt is called.
Or toggle a pin in the interrupt. Lots of ways to get there.