Hi
Can we use internal regulator for ref voltage of ADC of STM32L152? if you have experienced it please tel me how to do?
Which part exactly are you using? Some devices have +VREF internally bonded to VDDA, and -VREF internally bonded to VSSA. On devices with VREF pins *you* have to connect them to the supplies yourself, in your design. I'm reasonably sure there is not a magic software setting, but try reading the manuals.
Isn't VREFINT on CHANNEL 17?
www.st.com/.../CD00277537.pdf
Thanks for reply. I read by this command:
battery_val=ADC_Supply();
which calls
ADC_GetConversionValue(ADC1);
I have not connected VREF+ to any power source in my board is there a way to connect it internally to vref of MCU by software?
What values are you reading, and what do you expect to see?
I'm not sure the ADC *uses* it as a reference as much as it allows you to determine the value of your supplied +VREF
I am using
ADC_TempSensorVrefintCmd(ENABLE);
but it works with external vref my code is:
void ADC_Init(void) { ADC_InitTypeDef ADC_InitStructure; /* Enable ADC clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* de-initialize ADC */ ADC_DeInit(ADC1); /* ADC configured as follow: - NbrOfChannel = 1 - ADC_Channel_9 - Mode = Single ConversionMode(ContinuousConvMode disabled) - Resolution = 12Bits - Prescaler = /1 - sampling time 192 */ /* ADC Configuration */ ADC_StructInit(&ADC_InitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel9 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 1, ADC_SampleTime_192Cycles); ADC_DelaySelectionConfig(ADC1, ADC_DelayLength_Freeze); ADC_PowerDownCmd(ADC1, ADC_PowerDown_Idle_Delay, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Wait until ADC1 ON status */ while (ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET) { } }
uint16_t ADC_Supply(void) { uint8_t i; uint16_t res; /* Initializes ADC */ ADC_Init(); ADC_TempSensorVrefintCmd(ENABLE); /* ADC1 regular channel 9 for VREF configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 1, ADC_SampleTime_192Cycles); /* initialize result */ res = 0; for(i=4; i>0; i--) { /* start ADC convertion by software */ ADC_SoftwareStartConv(ADC1); /* wait until end-of-covertion */ while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 ); /* read ADC convertion result */ res += ADC_GetConversionValue(ADC1); } /* de-initialize ADC */ ADC_TempSensorVrefintCmd(DISABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, DISABLE); return (res>>2); }
View all questions in Keil forum