cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7A3 VBAT meassure

TWagn.2
Associate II

Hello,

I want to meassure the VBAT Voltage with the ADC2,

but it doesen't work.

I can meassure an intrease of the vbat current consumption from the voltage divder

when I activate the Channel Configuration. But I geht sample Values witch are way to low.

If I change the Channel to the VREF (also Rank 8) the sample values are correct.

Did I miss something?

	/* ADC2 controller clock enable */
	__HAL_RCC_ADC12_CLK_ENABLE();
 
	ADC_ChannelConfTypeDef sConfig = {0};
 
	/** Common config
	*/
	hadc.Instance = ADC2;
	hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
	hadc.Init.Resolution = ADC_RESOLUTION_16B;
	hadc.Init.ScanConvMode = ADC_SCAN_ENABLE;
	hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
	hadc.Init.LowPowerAutoWait = DISABLE;
	hadc.Init.ContinuousConvMode = DISABLE;
	hadc.Init.NbrOfConversion = 8;
	hadc.Init.DiscontinuousConvMode = DISABLE;
 
	hadc.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T15_TRGO;
	hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
 
	hadc.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
	hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
	hadc.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
	hadc.Init.OversamplingMode = DISABLE;
	if (HAL_ADC_Init(&hadc) != HAL_OK)
	{
		Error_Handler(ADC2_ERROR_INIT_PER);
	}
	/** Configure Regular Channel
	*/
	sConfig.Channel = ADC_CHANNEL_7;
	sConfig.Rank = ADC_REGULAR_RANK_1;
	sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5;
	sConfig.SingleDiff = ADC_SINGLE_ENDED;
	sConfig.OffsetNumber = ADC_OFFSET_NONE;
	sConfig.Offset = 0;
	sConfig.OffsetSignedSaturation = DISABLE;
	if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
	{
		Error_Handler(ADC2_ERROR_INIT_PER);
	}
 
....
	sConfig.Channel = ADC_CHANNEL_VBAT;
	sConfig.Rank = ADC_REGULAR_RANK_8;
	sConfig.SamplingTime = ADC_SAMPLETIME_810CYCLES_5;
	if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
	{
		Error_Handler(ADC2_ERROR_INIT_PER);
	}

4 REPLIES 4
TDK
Guru

What values do you get and what do you expect instead?

Note that the measurement is done on VBAT/4, not VBAT.

If you feel a post has answered your question, please click "Accept as Solution".
TWagn.2
Associate II

The output raw data for VBAT is 1531 +-20.

And I expact 2^16*3/3.3/4 = 14894

The output raw data for VREFINT is 25617

and for VREFINT I expect 2^16*1.216/3.3 = 24149

TDK
Guru

Make sure the VBATEN bit within ADCx->CCR is getting set. If that's not it, not sure.

If you feel a post has answered your question, please click "Accept as Solution".

Read out and check/post the ADC registers content.

Simplify the program to minimum complete compilable which exhibits the problem and post.

Do you have VBAT charging enabled by PWR_CR3.VBE? While the RM does not mention this to prevent VBAT measurement in ADC, I wouldn't be surprised if there would be some relationship.

JW