AnsweredAssumed Answered

3 channels on ADC1 and DMA

Question asked by Peden.Fabrice on Apr 10, 2013
Latest reply on Mar 7, 2014 by Sonu
Hi Everbody,

I'm trying to configure 3 channels of the ADC (Vbat, Temp and another analog input). Yesterday, I managed to read the value of Vbat. Now I would to read the value of the three channels, but I have '0' in my array.

I have started to initialize the DMA. I'm using DMA2 stream 0 (for ADC1 in the datasheet).

/* Initialize the DMA1 Channel1 according to the DMA_InitStructure members */
  DMA_InitTypeDef DMA_InitStructure;
  ADC_InitTypeDef       ADC_InitStructure;
  ADC_CommonInitTypeDef ADC_CommonInitStructure;
 
  /* Enable peripheral clocks *************************************************/
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
   
  DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4001204C;//ADC1_DR_ADDRESS;
  DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&ADCConvertedValue;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
  DMA_InitStructure.DMA_BufferSize = 3;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_Init(DMA2_Stream0, &DMA_InitStructure);
 
  /* Enable DMA1 Channel1 */
  DMA_Cmd(DMA2_Stream0, ENABLE);
         
  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Enabled;
  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
  ADC_CommonInit(&ADC_CommonInitStructure);
   
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfConversion = 1;
  ADC_Init(ADC1, &ADC_InitStructure);
 
  /* ADC1 regular channel18 (VBAT) configuration ******************************/
  ADC_RegularChannelConfig(ADC1, ADC_Channel_Vbat, 1, ADC_SampleTime_480Cycles);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_TempSensor, 2, ADC_SampleTime_15Cycles);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 3, ADC_SampleTime_15Cycles);
   
  /* Enable VBAT channel */
  ADC_VBATCmd(ENABLE);
 
  /* Enable Temp channel */
  ADC_TempSensorVrefintCmd(ENABLE);
   
  /* Enable ADC1 DMA transfer */
  ADC_DMACmd(ADC1, ENABLE);
 
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);
 
  /* Enable DMA request after last transfer (Single-ADC mode) */
  ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
 
  /* Enable ADC1 **************************************************************/
  ADC_Cmd(ADC1, ENABLE);
   
  ADC_SoftwareStartConv(ADC1);

Have you some ideas to suggest to me to help me to solve this problem ?

Thank you in advance,

Outcomes