stm32l1xx adc is giving random data after conversion done
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
