AnsweredAssumed Answered

STM32L152 Wrong ADC values

Question asked by farkash on May 3, 2015
Latest reply on May 3, 2015 by Clive One
Hello,

I'm working on custom board using STM32L152 chip.
Vref is : 3.19V
When i injuct to the analog pin 2.7 i read 4019 ,while 0 represent as 650.

(It seemed like 650 is the gap ????)
below my initialize ADC code :

/////////////////////////////////////////////
RCC_HSICmd(ENABLE);

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
  
 // Configuration CURRENT_SNS pins
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        a_opAdcControl->m_oAdcGpioControl.GPIO_Pin = GPIO_Pin_1;
        a_opAdcControl->m_oAdcGpioControl.GPIO_Mode = GPIO_Mode_AN;
        GPIO_Init(GPIOC, &a_opAdcControl->m_oAdcGpioControl);
       
  
 // Configuration Battary test
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  
// a_opAdcControl->m_oAdcGpioControl.GPIO_Pin = GPIO_Pin_4;
// a_opAdcControl->m_oAdcGpioControl.GPIO_Mode = GPIO_Mode_AN;
// GPIO_Init(GPIOA, &a_opAdcControl->m_oAdcGpioControl);

  
   // Check that HSI oscillator is ready
   while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);

 // ADC1 Configuration ------------------------------------------------------
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
 // ADC1 DeInit
 ADC_DeInit(ADC1);
  
 // ADC1 Configuration
 a_opAdcControl->m_oAdcInitControl.ADC_Resolution = ADC_Resolution_12b;
 a_opAdcControl->m_oAdcInitControl.ADC_ScanConvMode = DISABLE;// Disable multichannels
 a_opAdcControl->m_oAdcInitControl.ADC_ContinuousConvMode = DISABLE;// One Conversion at a time
 a_opAdcControl->m_oAdcInitControl.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//ADC_ExternalTrigConvEdge_Rising;//ADC_ExternalTrigConvEdge_Falling;
 a_opAdcControl->m_oAdcInitControl.ADC_ExternalTrigConv =0;
 a_opAdcControl->m_oAdcInitControl.ADC_DataAlign = ADC_DataAlign_Right;
 a_opAdcControl->m_oAdcInitControl.ADC_NbrOfConversion = 1;
 ADC_Init(ADC1, &a_opAdcControl->m_oAdcInitControl);
  
 // ADC1 Regular Channel Config
  
   
 // Enables the ADC1 Power Down during Delay
 ADC_PowerDownCmd(ADC1, ADC_PowerDown_Idle_Delay, ENABLE);
  
 // Delay until the converted data has been read
 ADC_DelaySelectionConfig(ADC1, ADC_DelayLength_Freeze);

 // Enable ADC1
 ADC_Cmd(ADC1, ENABLE);    
 
 // Wait until the ADC1 is ready
 while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)
 {
 }


////////////////////////////////////////////////////////////////
The code for reading ch :

// a_selCH = 0x0B (ch11 --> PC-1)

ADC_RegularChannelConfig(ADC1, a_selCH, 1, ADC_SampleTime_4Cycles);
  ADC_ClearFlag(ADC1,ADC_FLAG_EOC);
  // Start the conversion
  ADC_SoftwareStartConv(ADC1);
  // Wait until conversion completion
  while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET){}
  // Get the conversion value
  if (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == SET)
  {
    g_opAdcControl->m_oAdcChSample = ADC_GetConversionValue(ADC1);
  }
  ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
Please advise,

Outcomes