Skip to main content
leventeyigel52
Associate III
August 1, 2012
Question

Use ADC1's 2 Channel Problem

  • August 1, 2012
  • 3 replies
  • 708 views
Posted on August 01, 2012 at 10:34

uint16_t Read_OPTOLed_ADC1(void) 

{  

   ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1,    ADC_SampleTime_71Cycles5);

  

  ADC_SoftwareStartConvCmd(ADC1, ENABLE);

    

    while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); // Get the conversion value 

   

    OptoLedArray = ADC_GetConversionValue(ADC1);

        

   // return ADC_GetConversionValue(ADC1);

}

uint16_t Read_TEMP_ADC1(void) 

  ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_71Cycles5);

   

  while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); // Get the conversion value 

  

  TempArray = ADC_GetConversionValue(ADC1);  

  

 // return ADC_GetConversionValue(ADC1);

}

The ADC Configuration 

void ADC_Configuration (void)

  

  ADC_InitTypeDef ADC_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC| 

                         RCC_APB2Periph_ADC1, ENABLE);

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

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

  

  /* Configure PC4 (ADC Channel 7) as analog input -------------------------*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Configure PA7 (ADC Channel 14) as analog input -------------------------*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  

  

  /* ADC1 configuration ------------------------------------------------------*/

  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

  ADC_InitStructure.ADC_ScanConvMode = ENABLE;

  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfChannel = 2;

  ADC_Init(ADC1, &ADC_InitStructure);

  

  /* Enable ADC1 */

  ADC_Cmd(ADC1, ENABLE);

  /* Enable ADC1 reset calibaration register */   

  ADC_ResetCalibration(ADC1);

  /* Check the end of ADC1 reset calibration register */

  while(ADC_GetResetCalibrationStatus(ADC1));

  /* Start ADC1 calibaration */

  ADC_StartCalibration(ADC1);

  /* Check the end of ADC1 calibration */

  while(ADC_GetCalibrationStatus(ADC1));

     

  /* Start ADC1 Software Conversion */ 

 ADC_SoftwareStartConvCmd(ADC1, ENABLE);

  

}

PC.4 is ADC Channel 14 , PA.7 ADC Channel 7 ( Stm32 C-Eval )

I want to see this channels'  ADC Values but i see the same values at the same time.

Do i mistake at the configuration or ReadADC Function ?
    This topic has been closed for replies.

    3 replies

    raptorhal2
    Lead
    August 1, 2012
    Posted on August 01, 2012 at 15:32

    The ADC conversion register holds only one value. Change the initialization to:

    ADC_InitStructure.ADC_NbrOfChannel = 1;

    To convert two or more channels with one start conversion command, DMA is required. You are using two start conversions, which works also.

    Cheers, Hal

    leventeyigel52
    Associate III
    August 1, 2012
    Posted on August 01, 2012 at 15:58

    How can i add DMA for this configuration without interrupt ?

    raptorhal2
    Lead
    August 1, 2012
    Posted on August 01, 2012 at 17:15

    Poll the DMA current data counter. When = 0, all channels are converted and in the assigned buffer.

    See the Standard Peripheral Library example for ADC DMA to get started.

    Cheers, Hal