File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -17,13 +17,17 @@ use rt::entry;
17
17
#[ entry]
18
18
fn main ( ) -> ! {
19
19
let dp = stm32:: Peripherals :: take ( ) . expect ( "cannot take peripherals" ) ;
20
+ let cp = stm32:: CorePeripherals :: take ( ) . expect ( "cannot take core peripherals" ) ;
20
21
let mut rcc = dp. RCC . constrain ( ) ;
22
+ let mut delay = cp. SYST . delay ( & mut rcc) ;
21
23
22
24
let gpioa = dp. GPIOA . split ( & mut rcc) ;
23
25
24
26
let mut adc = dp. ADC . constrain ( & mut rcc) ;
25
27
adc. set_sample_time ( SampleTime :: T_80 ) ;
26
28
adc. set_precision ( Precision :: B_12 ) ;
29
+ delay. delay ( 20 . us ( ) ) ; // Wait for ADC voltage regulator to stabilize
30
+ adc. calibrate ( ) ;
27
31
28
32
let mut adc_pin = gpioa. pa0 . into_analog ( ) ;
29
33
let mut vtemp = VTemp :: new ( ) ;
Original file line number Diff line number Diff line change @@ -68,6 +68,17 @@ impl Adc {
68
68
}
69
69
}
70
70
71
+ /// Runs the calibration routine on the ADC
72
+ ///
73
+ /// Wait for tADCVREG_SETUP (20us on STM32G071x8) after calling `new()`
74
+ /// before calibrating, to wait for the ADC voltage regulator to stabilize.
75
+ ///
76
+ /// Do not call if an ADC reading is ongoing.
77
+ pub fn calibrate ( & mut self ) {
78
+ self . rb . cr . modify ( |_, w| w. adcal ( ) . set_bit ( ) ) ;
79
+ while self . rb . cr . read ( ) . adcal ( ) . bit_is_set ( ) { }
80
+ }
81
+
71
82
/// Set the Adc sampling time
72
83
pub fn set_sample_time ( & mut self , t_samp : SampleTime ) {
73
84
self . sample_time = t_samp;
You can’t perform that action at this time.
0 commit comments