Skip to content

Commit 596670b

Browse files
committed
cpu/stm32f2: fix sampling time for VBat
1 parent 4f676cd commit 596670b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cpu/stm32/periph/adc_f2.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ int adc_init(adc_t line)
9696
assume((periph_apb_clk(APB2) / clk_div) <= ADC_CLK_MAX);
9797
ADC->CCR = ((clk_div / 2) - 1) << 16;
9898

99+
if (IS_USED(MODULE_PERIPH_VBAT)) {
100+
/* Set the sampling rate for the VBat channel to 112 cycles. It reads
101+
* correct with 84 cycles already, so this adds some margin. */
102+
ADC1->SMPR1 = (ADC1->SMPR1 & ~ADC_SMPR1_SMP18) | \
103+
(ADC_SMPR1_SMP18_2 | ADC_SMPR1_SMP18_0);
104+
}
105+
99106
/* enable the ADC module */
100107
dev(line)->CR2 = ADC_CR2_ADON;
101108

0 commit comments

Comments
 (0)