pub struct Adc { /* private fields */ }
Expand description
Analog to Digital converter interface
Implementations§
Source§impl Adc
impl Adc
pub fn new(adc: ADC, rcc: &mut Rcc) -> Self
Sourcepub fn set_clock_source(&mut self, clock_source: ClockSource)
pub fn set_clock_source(&mut self, clock_source: ClockSource)
Sets ADC source
Sourcepub fn calibrate(&mut self)
pub fn calibrate(&mut self)
Runs the calibration routine on the ADC
Wait for tADCVREG_SETUP (20us on STM32G071x8) after calling Self::new()
before calibrating, to wait for the
ADC voltage regulator to stabilize.
Do not call if an ADC reading is ongoing.
Sourcepub fn get_calibration(&self) -> CalibrationFactor
pub fn get_calibration(&self) -> CalibrationFactor
Returns the calibration factors used by the ADC
The ADC does not have a factory-stored calibration, Self::calibrate()
must be run before calling this
for the returned value to be useful.
The ADC loses its calibration factors when Standby or Vbat mode is entered. Saving and restoring the calibration factors can be used to recalibrate the ADC after waking up from sleep more quickly than re-running calibraiton. Note that VDDA changes and to a lesser extent temperature changes affect the ADC operating conditions and calibration should be run again for the best accuracy.
Sourcepub fn set_calibration(&mut self, calfact: CalibrationFactor)
pub fn set_calibration(&mut self, calfact: CalibrationFactor)
Writes the calibration factors used by the ADC
Do not call if an ADC reading is ongoing.
Sourcepub fn set_sample_time(&mut self, t_samp: SampleTime)
pub fn set_sample_time(&mut self, t_samp: SampleTime)
Set the Adc sampling time
Sourcepub fn set_precision(&mut self, precision: Precision)
pub fn set_precision(&mut self, precision: Precision)
Set the Adc precision
Sourcepub fn set_oversampling_shift(&mut self, nrbits: u8)
pub fn set_oversampling_shift(&mut self, nrbits: u8)
The nuber of bits, the oversampling result is shifted in bits at the end of oversampling
Sourcepub fn set_oversampling_ratio(&mut self, ratio: OversamplingRatio)
pub fn set_oversampling_ratio(&mut self, ratio: OversamplingRatio)
Oversampling of adc according to datasheet of stm32g0, when oversampling is enabled
pub fn oversampling_enable(&mut self, enable: bool)
pub fn start_injected(&mut self)
pub fn stop_injected(&mut self)
Sourcepub fn read_vref(&mut self) -> Result<u16, ()>
pub fn read_vref(&mut self) -> Result<u16, ()>
Read actual VREF voltage using the internal reference
If oversampling is enabled, the return value is scaled down accordingly. The product of the return value and any ADC reading always gives correct voltage in 4096ths of mV regardless of oversampling and shift settings provided that these settings remain the same.
Sourcepub fn get_vref_cached(&mut self) -> Result<u16, ()>
pub fn get_vref_cached(&mut self) -> Result<u16, ()>
Get VREF value using cached value if possible
See read_vref
for more details.