Skip to main content
bigfede94
Associate II
November 4, 2022
Question

STM32F1 ADC Dual regular simultaneous mode only, wrong position of ADC2 samples with DMA

Hello,

I'm facing issues withering the "Dual regular simultaneous mode" on STM32F103C8T.

Basically a timer shall trigger both ADC to convert (for each ADC) 5 channels.

What I've observed is that samples from ADC1 are ok, but samples from ADC2 have wrong position into the buffer. Can you please help me understanding if my configuration si correct or not?

#define MAX_ADC_CHANNELS 10
 
#define ADC1_RESULT(DATA) \
 ((DATA) & 0x0000FFFF)
 
#define ADC2_RESULT(DATA) \
 ((DATA) >> 16)
 
uint32_t ADCfromDMA[MAX_ADC_CHANNELS/2] = {0x00000000};
 
void ADCInit(uint8_t id, char* task_name)
{
 HAL_ADCEx_Calibration_Start(&hadc1);
 HAL_ADCEx_Calibration_Start(&hadc2);
 
 HAL_TIM_Base_Start(&htim3);
 
 HAL_ADC_Start(&hadc2);
 
 HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)ADCfromDMA, MAX_ADC_CHANNELS/2);
 
}
 
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *AdcHandle)
{
 /*Read adc values upper & lower from DMA*/
 ADCRawData[0] = ADC1_RESULT(ADCfromDMA[0]); //ok
 ADCRawData[1] = ADC2_RESULT(ADCfromDMA[0]); //ok
 
 ADCRawData[2] = ADC1_RESULT(ADCfromDMA[1]); //ok
 ADCRawData[3] = ADC2_RESULT(ADCfromDMA[1]); //ok
 
 ADCRawData[4] = ADC1_RESULT(ADCfromDMA[2]); //
 ADCRawData[5] = ADC2_RESULT(ADCfromDMA[2]); //
 ADCRawData[6] = ADC1_RESULT(ADCfromDMA[3]); //
 ADCRawData[7] = ADC2_RESULT(ADCfromDMA[3]); //
 ADCRawData[8] = ADC1_RESULT(ADCfromDMA[4]); //
 ADCRawData[9] = ADC2_RESULT(ADCfromDMA[4]); //
 
}

This topic has been closed for replies.

9 replies

Javier1
Principal
November 4, 2022

a similar thing happened to me.

I wasnt giving the DMA enough time to fill the buffer.

Are you using HAL_ADCEx_MultiModeStop_DMA()?

hit me up in https://www.linkedin.com/in/javiermuñoz/
bigfede94
bigfede94Author
Associate II
November 4, 2022

That sounds interesting. No I'm not using any Stop function. Have you any example?

Javier1
Principal
November 4, 2022

i dont have any example on hand but you should be able to debug it yourself.

Is the DMA in circular mode?

Also triplecheck the size of the variables DMA expects matches the one you are using

hit me up in https://www.linkedin.com/in/javiermuñoz/
bigfede94
bigfede94Author
Associate II
November 4, 2022

Yes, now is working in circular mode. Actually I have not completely understand how callbacks works for the DMA. Like Half and Complete. Any hint?

AKhot.1
Associate III
June 6, 2023

Hi, I need help with the ioc settings and I didn't understand the first two defines. Can you please help me with this?