cancel
Showing results for 
Search instead for 
Did you mean: 

ADC multi channel & DMA reads only first channel

Osto
Senior
Posted on May 16, 2015 at 18:34

I have a project with 3 channels DMA with STM32F407VGT (STM32F4-Discovery). The channels 2,3 and 4 (PA2, PA3, PA4) are used to read the ADC values. Its enough to read the values every 10 seconds. So the poling mode is also good enough. I tried Regolar poling, regular with Interrup, injected polling,.... but have always the same problem. The ADC/DMA ready only the first channel and not second or third channel. with below config, DMA and 3 regular Channels which is produced by MxCube.

  &sharpinclude ''adc.h''

&sharpinclude ''gpio.h''

&sharpinclude ''dma.h''

ADC_HandleTypeDef hadc1;

DMA_HandleTypeDef hdma_adc1;

void MX_ADC1_Init(void)

{

  ADC_ChannelConfTypeDef sConfig;

  hadc1.Instance = ADC1;

  hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV8;

  hadc1.Init.Resolution = ADC_RESOLUTION12b;

  hadc1.Init.ScanConvMode = DISABLE;

  hadc1.Init.ContinuousConvMode = DISABLE;

  hadc1.Init.DiscontinuousConvMode = DISABLE;

  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

  hadc1.Init.NbrOfConversion = 3;

  hadc1.Init.DMAContinuousRequests = ENABLE;

  hadc1.Init.EOCSelection = EOC_SINGLE_CONV;

  HAL_ADC_Init(&hadc1);

  sConfig.Channel = ADC_CHANNEL_2;

  sConfig.Rank = 1;

  sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

  sConfig.Channel = ADC_CHANNEL_3;

  sConfig.Rank = 2;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

  sConfig.Channel = ADC_CHANNEL_4;

  sConfig.Rank = 3;

  HAL_ADC_ConfigChannel(&hadc1, &sConfig);

}

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)

{

  GPIO_InitTypeDef GPIO_InitStruct;

  if(hadc->Instance==ADC1)

  {

    __ADC1_CLK_ENABLE();

  

    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4;

    GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    hdma_adc1.Instance = DMA2_Stream0;

    hdma_adc1.Init.Channel = DMA_CHANNEL_0;

    hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;

    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;

    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;

    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

    hdma_adc1.Init.Mode = DMA_NORMAL;

    hdma_adc1.Init.Priority = DMA_PRIORITY_MEDIUM;

    hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

    HAL_DMA_Init(&hdma_adc1);

    __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);

  }

}

void main()

{

uint16_t ADValues[3];

HAL_ADC_MspInit();

MX_DMA_Init();

MX_ADC1_Init();

HAL_ADC_Start_DMA(&hadc1, (uint32_t *)&ADValues[0], 3);

}

Wahts is the problem? Can somebody help me?

Thanls a lot in advance for your help.

Osto

#adc
4 REPLIES 4
Posted on May 16, 2015 at 18:41

hadc1.Init.ScanConvMode = DISABLE;

// << Probably want it to be scanning the channels?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
raptorhal2
Lead
Posted on May 16, 2015 at 20:08

It's Discovery deja vu all over again.

PA4 is also connected to the board audio codec's LRCK pin. Suggest changing to ADC channels 1, 2 and 3.

Cheers, Hal

Osto
Senior
Posted on May 16, 2015 at 23:53

Thanks clive. That was the problem.

Osto
Senior
Posted on May 16, 2015 at 23:54

Yes, I know that PA4 pin is in use.

I removed the chip from the board.