Struct stm32f1xx_hal::adc::Adc
source · pub struct Adc<ADC> { /* private fields */ }
Expand description
ADC configuration
Implementations§
source§impl Adc<ADC1>
impl Adc<ADC1>
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.
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()
source§impl Adc<ADC1>
impl Adc<ADC1>
sourcepub fn adc1(adc: ADC1, clocks: Clocks) -> Self
pub fn adc1(adc: ADC1, clocks: Clocks) -> 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: EXTSEL_A)
source§impl Adc<ADC2>
impl Adc<ADC2>
sourcepub fn adc2(adc: ADC2, clocks: Clocks) -> Self
pub fn adc2(adc: ADC2, clocks: Clocks) -> 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: EXTSEL_A)
source§impl Adc<ADC3>
impl Adc<ADC3>
sourcepub fn adc3(adc: ADC3, clocks: Clocks) -> Self
pub fn adc3(adc: ADC3, clocks: Clocks) -> 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