2013-10-30 03:57 AM
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, 2..
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.
2013-10-30 04:47 AM
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);?2013-10-30 05:06 AM
Oh, bloody hell, you are right I fogot about SYSCFG RCC. Intresting that in STM32F37x_StdPeriph_Examples there is no RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); and no SYSCFG_VBATMonitoringCmd(ENABLE);
Thanks. ________________ Attachments : main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0hr&d=%2Fa%2F0X0000000be2%2F07ADvet3CLBe_eeVB0beC5s2i7UJCWnXmBjJmMxGmRc&asPdf=false