cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l1xx adc is giving random data after conversion done

es.18
Associate II

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

4 REPLIES 4
Uwe Bonnes
Principal III

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

S.Ma
Principal

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

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???

es.18
Associate II

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???