cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f0 adc dma multi channel problem

superK
Associate II

1.  ADC setting

hadc.Instance = ADC1;

  hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;

  hadc.Init.Resolution = ADC_RESOLUTION_12B;

  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;

  hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

  hadc.Init.LowPowerAutoWait = DISABLE;

  hadc.Init.LowPowerAutoPowerOff = DISABLE;

  hadc.Init.ContinuousConvMode = ENABLE;

  hadc.Init.DiscontinuousConvMode = DISABLE;

  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;

  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc.Init.DMAContinuousRequests = ENABLE;

  hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;

  if (HAL_ADC_Init(&hadc) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_4;

  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;

  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_5;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_6;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_7;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_8;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

  /** Configure for the selected ADC regular channel to be converted.

  */

  sConfig.Channel = ADC_CHANNEL_9;

  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)

  {

    Error_Handler();

  }

////////////////////////////////////////////////////////////////////////////////////////

2.DMA Setting

 hdma_adc.Instance = DMA1_Channel1;

    hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY;

    hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_adc.Init.MemInc = DMA_MINC_ENABLE;

    hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

    hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

    hdma_adc.Init.Mode = DMA_CIRCULAR;

    hdma_adc.Init.Priority = DMA_PRIORITY_VERY_HIGH;

    if (HAL_DMA_Init(&hdma_adc) != HAL_OK)

    {

      Error_Handler();

    }

3. DMA START

unsigned short Test_adc[6];

 HAL_ADC_Start_DMA(&hadc,(uint32_t *)Test_adc,6);

Results of testing with ADC DMA configured in the Cube IDE

Only the first value is sampled and entered.

Please tell me what should be corrected to convert correctly.

1 ACCEPTED SOLUTION

Accepted Solutions
TETRAVAL
Associate

"Your ADC & DMA are well configured. Please make sure that MX_DMA_Init(); is called before MX_ADC_Init();

It should work like that."

in my code dma is defined before adc but still sample from dma adc once and i set dma circular mode i not set dma normal mode

View solution in original post

2 REPLIES 2
GwenoleB
ST Employee

Hello @superK​,

Your ADC & DMA are well configured. Please make sure that MX_DMA_Init(); is called before MX_ADC_Init();

It should work like that.

Best Regards,

Gwénolé

TETRAVAL
Associate

"Your ADC & DMA are well configured. Please make sure that MX_DMA_Init(); is called before MX_ADC_Init();

It should work like that."

in my code dma is defined before adc but still sample from dma adc once and i set dma circular mode i not set dma normal mode