Skip to main content
es.18
Associate
January 2, 2019
Question

stm32l1xx adc is giving random data after conversion done

  • January 2, 2019
  • 4 replies
  • 1194 views

hi,

we are trying to measure vrefint using adc of stm32l1xx. the converted data is keep on varying between 0 to 3000 (decimal). we are not sure where is the problem. can anyone help on this issue? here is the sample code:

//hsi clock is enabled in startup

 ADC_BankSelection(ADC1, ADC_Bank_A);

 ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

 ADC_InitStructure.ADC_ScanConvMode = DISABLE;

 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T9_CC2;

 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

 ADC_InitStructure.ADC_NbrOfConversion = 1;

 ADC_Init(ADC1, &ADC_InitStructure);

ADC->CCR |= 1 << 23; //enable vrefint

 ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 1, ADC_SampleTime_4Cycles);

 ADC_Cmd(ADC1, ENABLE);   

 /* Wait until the ADC1 is ready */

 while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)

 {

 }

ADC_SoftwareStartConv(ADC1);

 while (1)

 { 

if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC))

{

ADC_ConvertedValue = ADC_GetConversionValue(ADC1);

printf("\r\n data = %d ", ADC_ConvertedValue);

for(i=0;i<800000;i++);

ADC_SoftwareStartConv(ADC1);

}

 }

tried with different system clock (msi, hsi, hse). but still converted data is keep on changing.

thanks ,

elavarasan s

This topic has been closed for replies.

4 replies

Uwe Bonnes
Chief
January 2, 2019

Look in the datasheet and reference manual. ADC_SampleTime_4Cycles seems very short.

es.18
es.18Author
Associate
January 3, 2019

i tried with all sample rates. but result is same. we have checked one more analog input (2.5v) is connected with PC5. getting the same result. getting random data after conversion. strange. we are missing something???

S.Ma
Principal
January 2, 2019

Check if there is a power enable control bit for Vref block. (ref man)

es.18
es.18Author
Associate
January 3, 2019

there is no power enable for vref. but VREFINTRDYF is set in PWR_CSR register. we have checked one more analog input (2.5v) is connected with PC5. getting the same result. getting random data after conversion. strange. are we missing something???