pub struct Adc<ADC> { /* private fields */ }
Expand description
ADC configuration
Implementations§
Source§impl<ADC: Instance> Adc<ADC>
impl<ADC: Instance> Adc<ADC>
Sourcepub fn new(adc: ADC, rcc: &mut Rcc) -> Self
pub fn new(adc: ADC, rcc: &mut Rcc) -> Self
Init a new Adc
Sets all configurable parameters to one-shot defaults, performs a boot-time calibration.
Sourcepub fn save_cfg(&mut self) -> StoredConfig
pub fn save_cfg(&mut self) -> StoredConfig
Save current ADC config
Sourcepub fn restore_cfg(&mut self, cfg: StoredConfig)
pub fn restore_cfg(&mut self, cfg: StoredConfig)
Restore saved ADC config
Sourcepub fn default_cfg(&mut self) -> StoredConfig
pub fn default_cfg(&mut self) -> StoredConfig
Reset the ADC config to default, return existing config
Sourcepub fn set_sample_time(&mut self, t_samp: SampleTime)
pub fn set_sample_time(&mut self, t_samp: SampleTime)
Set ADC sampling time
Options can be found in SampleTime.
Sourcepub fn set_align(&mut self, align: Align)
pub fn set_align(&mut self, align: Align)
Set the Adc result alignment
Options can be found in Align.
Sourcepub fn max_sample(&self) -> u16
pub fn max_sample(&self) -> u16
Returns the largest possible sample value for the current settings
pub fn set_external_trigger(&mut self, trigger: ADC::ExtSel)
Sourcepub fn release(self, rcc: &mut RCC) -> ADC
pub fn release(self, rcc: &mut RCC) -> ADC
Powers down the ADC, disables the ADC clock and releases the ADC Peripheral
Sourcepub fn enable_eoc_interrupt(&mut self)
pub fn enable_eoc_interrupt(&mut self)
Enable interrupt for EOC (end of convert)
Sourcepub fn disable_eoc_interrupt(&mut self)
pub fn disable_eoc_interrupt(&mut self)
Disable interrupt for EOC (end of convert)
Sourcepub fn enable_jeoc_interrupt(&mut self)
pub fn enable_jeoc_interrupt(&mut self)
Enable interrupt for JEOC (EOC for injected channels)
Sourcepub fn disable_jeoc_interrupt(&mut self)
pub fn disable_jeoc_interrupt(&mut self)
Disable interrupt for JEOC (EOC for injected channels)
Source§impl Adc<ADC1>
impl Adc<ADC1>
Sourcepub fn enable_temp_vref(&mut self) -> bool
pub fn enable_temp_vref(&mut self) -> bool
Enables the temperature / VREF sensor.
Enabling this before calling read_temp
or read_vref
will speed up the reading
since you won’t have to wait for the sensor to start up.
Returns true if the sensor was previously off.
Sourcepub fn disable_temp_vref(&mut self)
pub fn disable_temp_vref(&mut self)
Disables the temperature / VREF sensor.
read_temp
and read_vref
will still work with this disabled, but will take a
bit longer since you have to wait for the sensor to start up.
pub fn is_temp_vref_enabled(&self) -> bool
Sourcepub fn read_temp(&mut self) -> i32
pub fn read_temp(&mut self) -> i32
Temperature sensor is connected to channel 16 on ADC1. This sensor can be used to measure ambient temperature of the device. However note that the returned value is not an absolute temperature value.
In particular, according to section 11.10 from Reference Manual RM0008 Rev 20: “The temperature sensor output voltage changes linearly with temperature. The offset of this line varies from chip to chip due to process variation (up to 45 °C from one chip to another). The internal temperature sensor is more suited to applications that detect temperature variations instead of absolute temperatures. If accurate temperature readings are needed, an external temperature sensor part should be used.”
Formula to calculate temperature value is also taken from the section 11.10.
If the temp/VREF sensor is disabled, this will still work but must wait
for the sensor to start up. Call enable_temp_vref
to speed this up.
Sourcepub fn read_vref(&mut self) -> u16
pub fn read_vref(&mut self) -> u16
Internal reference voltage Vrefint is connected to channel 17 on ADC1. According to section 5.3.4 “Embedded reference voltage” from STM32F1xx datasheets, typical value of this reference voltage is 1200 mV.
This value is useful when ADC readings need to be converted into voltages. For instance, reading from any ADC channel can be converted into voltage (mV) using the following formula: v_chan = adc.read(chan) * 1200 / adc.read_vref()
If the temp/VREF sensor is disabled, this will still work but must wait
for the sensor to start up. Call enable_temp_vref
to speed this up.