AnsweredAssumed Answered

STM32F3 Vbat monitoring problem

Question asked by genius.cyber on Oct 30, 2013
Latest reply on Oct 30, 2013 by genius.cyber
Hello.
STM32F373C8, IAR
I have a problem with monitoring battary charge on Vbat pin by internal ADC1 channel. I configurated phy like in stm32f37x_dsp_stdperiph_lib but it dosn't works right. My code:

void Vbat_Init( void )
{
 ADC_InitTypeDef ADC_InitStructure;
 
 RCC_ADCCLKConfig( RCC_PCLK2_Div4 );
 
 RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1, ENABLE );
 
 ADC_DeInit( ADC1 );
 
 ADC_StructInit( &ADC_InitStructure );
 
 ADC_InitStructure.ADC_ScanConvMode = DISABLE;
 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
 ADC_InitStructure.ADC_NbrOfChannel = 1;
 ADC_Init( ADC1, &ADC_InitStructure );
 
 SYSCFG_VBATMonitoringCmd(ENABLE);
 
 ADC_RegularChannelConfig( ADC1, ADC_Channel_Vbat, 1, ADC_SampleTime_239Cycles5 );
 
 ADC_Cmd( ADC1, ENABLE );
 
 ADC_ResetCalibration( ADC1 );
 
 while( ADC_GetResetCalibrationStatus(ADC1) );
 
 ADC_StartCalibration( ADC1 );
 
 while( ADC_GetCalibrationStatus(ADC1) );
 
 ADC_Cmd( ADC1, ENABLE );
}
 
 
int main( void )
{
 Vbat_Init();
 __IO static uint16_t BatV;
 while( 1 )
 {
  __delay_ms( 100 );
  BatV = ADC_GetConversionValue( ADC1 );
 }
}

And I get values such: 2041, 2066, 2175, 2066, 2063, 2048, 2066, 2215, 2045...
It's not right values and I try to change voltage on Vbat pin, try different battaries or disassembly it all, nothing changes.

And at the same time if I try measure temperature it's all ok.
I looked in other forums but didn't help.

Outcomes