AnsweredAssumed Answered

Multiple ADC STM32F303 discovery board

Question asked by Lucretius_Fermius on Jul 9, 2013
Latest reply on Oct 14, 2015 by AvaTar

Hi.
I know this topic was discussed before, but not for STM32F303. So, I would just like to read analog value on the GPIOC  pin0, pin1, pin3. My program returns all values equal to zero. I don't know why and what am I doing wrong.
I would realy appreciated some help.



unsigned short ADC_Values[3];
unsigned short adc_pin0;
unsigned short adc_pin1;
unsigned short adc_pin3;

int main(void)

{

 

  /* Configure the ADC clock
  RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);

  /* Enable ADC1 clock */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);

     

  /* Setup SysTick Timer for 1 µsec interrupts  */

  if (SysTick_Config(SystemCoreClock / 1000000))

  {

    /* Capture error */

    while (1)

    {}

  }

               

                /*** DMA ***/

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);

               

                DMA_InitStructure.DMA_BufferSize=3;

                DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;

                DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)&ADC_Values[0];

                DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize_Word;

                DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable ;

                DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;

                DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_BASE;

                DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord ;

                DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable; 

                DMA_InitStructure.DMA_Priority=DMA_Priority_High;

                DMA_Init(DMA1_Channel1, &DMA_InitStructure);

                LED_On_color(GREEN);

 

  /* ADC Channel configuration */

  /* GPIOC Periph clock enable */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

 

  /* Configure ADC Channel7 as analog input */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3 ;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

 

  ADC_StructInit(&ADC_InitStructure);

 

  /* Calibration procedure */ 

  ADC_VoltageRegulatorCmd(ADC1, ENABLE);

 

  /* Insert delay equal to 10 µs */

  Delay(10);

 

  ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);

  ADC_StartCalibration(ADC1);

 

  while(ADC_GetCalibrationStatus(ADC1) != RESET );

  calibration_value = ADC_GetCalibrationValue(ADC1);

    

  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;                                                                   

  ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;                   

  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;            

  ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;                 

  ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;         

  ADC_CommonInit(ADC1, &ADC_CommonInitStructure);

 

  ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

  ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;        

  ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;  

  ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable; 

  ADC_InitStructure.ADC_NbrOfRegChannel = 3;

  ADC_Init(ADC1, &ADC_InitStructure);

 

  /* ADC1 regular channel7 configuration */

  ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_7Cycles5);

  ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 2, ADC_SampleTime_7Cycles5);

  ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 3, ADC_SampleTime_7Cycles5);              

 

               

                DMA_ITConfig( DMA1_Channel1, DMA_IT_TC, ENABLE );

  DMA_Cmd(DMA1_Channel1, ENABLE);

               

                ADC_DMACmd(ADC1, ENABLE);

                /* Enable ADC1 */

  ADC_Cmd(ADC1, ENABLE);

                ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

 

  NVIC_SetPriority(ADC1_2_IRQn, 0);

  NVIC_EnableIRQ(ADC1_2_IRQn);

 

  ADC_GetConversionValue(ADC1);

               

  /* Start ADC1 Software Conversion */

  ADC_StartConversion(ADC1);  

 

  /* Infinite loop */

  while (1)

  {

                                                             

                               adc_pin0 = ADC_Values [0];

                               adc_pin1 = ADC_Values [1];

                               adc_pin3 = ADC_Values [2];

  }

}

Outcomes