cancel
Showing results for 
Search instead for 
Did you mean: 

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

bigfede94
Associate II

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]); //
 
}

9 REPLIES 9
Javier1
Principal

a similar thing happened to me.

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

Are you using HAL_ADCEx_MultiModeStop_DMA()?

we dont need to firmware by ourselves, lets talk
bigfede94
Associate II

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

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

we dont need to firmware by ourselves, lets talk

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?

even ifthe buffer is treated as circular, it has beginning and end.

When the DMA reaches the ened of the buffer it will trigger transaction Complete Calback.

When the DMA reaches mid point of the buffer it will trigger transaction Half way Callback.

Both are usefull just for your core to work more in sync with DMA, doing time critical stuff.

we dont need to firmware by ourselves, lets talk

That's good. But if the buffer is composed of 5 elements? When the Half callback is called?

good question, i have no clue

we dont need to firmware by ourselves, lets talk

:) best way to find out is to try it ! Did you do that ?

AKhot.1
Senior

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