Struct stm32f4xx_hal::adc::Adc
source · pub struct Adc<ADC> { /* private fields */ }
Expand description
Analog to Digital Converter
Implementations§
source§impl Adc<ADC1>
impl Adc<ADC1>
sourcepub fn calibrate(&mut self)
pub fn calibrate(&mut self)
Calculates the system VDDA by sampling the internal VREF channel and comparing the result with the value stored at the factory.
sourcepub fn enable_vbat(&self)
pub fn enable_vbat(&self)
Enables the vbat internal channel
sourcepub fn disable_vbat(&self)
pub fn disable_vbat(&self)
Enables the vbat internal channel
sourcepub fn enable_temperature_and_vref(&mut self)
pub fn enable_temperature_and_vref(&mut self)
Enables the temp and vref internal channels. They can’t work while vbat is also enabled so this method also disables vbat.
sourcepub fn disable_temperature_and_vref(&mut self)
pub fn disable_temperature_and_vref(&mut self)
Disables the temp and vref internal channels
sourcepub fn temperature_and_vref_enabled(&mut self) -> bool
pub fn temperature_and_vref_enabled(&mut self) -> bool
Returns if the temp and vref internal channels are enabled
sourcepub fn adc1(adc: ADC1, reset: bool, config: AdcConfig) -> Adc<ADC1>
pub fn adc1(adc: ADC1, reset: bool, config: AdcConfig) -> Adc<ADC1>
Enables the ADC clock, resets the peripheral (optionally), runs calibration and applies the supplied config
Arguments
reset
- should a reset be performed. This is provided because on some devices multiple ADCs share the same common reset
sourcepub fn apply_config(&mut self, config: AdcConfig)
pub fn apply_config(&mut self, config: AdcConfig)
Applies all fields in AdcConfig
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns if the adc is enabled
sourcepub fn disable(&mut self)
pub fn disable(&mut self)
Disables the adc
Note
The ADC in the f4 has few restrictions on what can be configured while the ADC is enabled. If any bugs are found where some settings aren’t “sticking” try disabling the ADC before changing them. The reference manual for the chip I’m using only states that the sequence registers are locked when they are being converted.
sourcepub fn start_conversion(&mut self)
pub fn start_conversion(&mut self)
Starts conversion sequence. Waits for the hardware to indicate it’s actually started.
sourcepub fn set_resolution(&mut self, resolution: Resolution)
pub fn set_resolution(&mut self, resolution: Resolution)
Sets the sampling resolution
sourcepub fn set_external_trigger(
&mut self,
(edge, extsel): (TriggerMode, ExternalTrigger)
)
pub fn set_external_trigger( &mut self, (edge, extsel): (TriggerMode, ExternalTrigger) )
Sets which external trigger to use and if it is disabled, rising, falling or both
sourcepub fn set_continuous(&mut self, continuous: Continuous)
pub fn set_continuous(&mut self, continuous: Continuous)
Enables and disables continuous mode
sourcepub fn set_end_of_conversion_interrupt(&mut self, eoc: Eoc)
pub fn set_end_of_conversion_interrupt(&mut self, eoc: Eoc)
Sets if the end-of-conversion behaviour. The end-of-conversion interrupt occur either per conversion or for the whole sequence.
sourcepub fn clear_end_of_conversion_flag(&mut self)
pub fn clear_end_of_conversion_flag(&mut self)
Resets the end-of-conversion flag
sourcepub fn set_default_sample_time(&mut self, sample_time: SampleTime)
pub fn set_default_sample_time(&mut self, sample_time: SampleTime)
Sets the default sample time that is used for one-shot conversions.
configure_channel and start_conversion can be
used for configurations where different sampling times are required per channel.
sourcepub fn sequence_length(&mut self) -> u8
pub fn sequence_length(&mut self) -> u8
Returns the current sequence length. Primarily useful for configuring DMA.
sourcepub fn reset_sequence(&mut self)
pub fn reset_sequence(&mut self)
Reset the sequence
sourcepub fn data_register_address(&mut self) -> u32
pub fn data_register_address(&mut self) -> u32
Returns the address of the ADC data register. Primarily useful for configuring DMA.
sourcepub fn configure_channel<CHANNEL>(
&mut self,
_channel: &CHANNEL,
sequence: Sequence,
sample_time: SampleTime
)
pub fn configure_channel<CHANNEL>( &mut self, _channel: &CHANNEL, sequence: Sequence, sample_time: SampleTime )
Configure a channel for sampling.
It will make sure the sequence is at least as long as the sequence
provided.
Arguments
channel
- channel to configuresequence
- where in the sequence to sample the channel. Also called rank in some STM docs/codesample_time
- how long to sample for. See datasheet and ref manual to work out how long you need
to sample for at a given ADC clock frequency
sourcepub fn current_sample(&self) -> u16
pub fn current_sample(&self) -> u16
Returns the current sample stored in the ADC data register
sourcepub fn sample_to_millivolts(&self, sample: u16) -> u16
pub fn sample_to_millivolts(&self, sample: u16) -> u16
Converts a sample value to millivolts using calibrated VDDA and configured resolution. Due to the ADC characteristics VDDA will never be reached as described in #362 and AN2834-How to get the best ADC accuracy in STM32 microcontrollers in section 3.1.2.
sourcepub fn make_sample_to_millivolts(&self) -> impl Fn(u16) -> u16
pub fn make_sample_to_millivolts(&self) -> impl Fn(u16) -> u16
Make a converter for samples to millivolts
sourcepub fn reference_voltage(&self) -> u32
pub fn reference_voltage(&self) -> u32
Returns the VDDA in millivolts calculated from the factory calibration and vrefint. Can be used to get calibration data from ADC1 and use it to configure ADCs that don’t support calibration.
sourcepub fn wait_for_conversion_sequence(&self)
pub fn wait_for_conversion_sequence(&self)
Block until the conversion is completed
Panics
Will panic if there is no conversion started and the end-of-conversion bit is not set
source§impl Adc<ADC2>
impl Adc<ADC2>
sourcepub fn adc2(adc: ADC2, reset: bool, config: AdcConfig) -> Adc<ADC2>
pub fn adc2(adc: ADC2, reset: bool, config: AdcConfig) -> Adc<ADC2>
Enables the ADC clock, resets the peripheral (optionally), runs calibration and applies the supplied config
Arguments
reset
- should a reset be performed. This is provided because on some devices multiple ADCs share the same common reset
sourcepub fn apply_config(&mut self, config: AdcConfig)
pub fn apply_config(&mut self, config: AdcConfig)
Applies all fields in AdcConfig
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns if the adc is enabled
sourcepub fn disable(&mut self)
pub fn disable(&mut self)
Disables the adc
Note
The ADC in the f4 has few restrictions on what can be configured while the ADC is enabled. If any bugs are found where some settings aren’t “sticking” try disabling the ADC before changing them. The reference manual for the chip I’m using only states that the sequence registers are locked when they are being converted.
sourcepub fn start_conversion(&mut self)
pub fn start_conversion(&mut self)
Starts conversion sequence. Waits for the hardware to indicate it’s actually started.
sourcepub fn set_resolution(&mut self, resolution: Resolution)
pub fn set_resolution(&mut self, resolution: Resolution)
Sets the sampling resolution
sourcepub fn set_external_trigger(
&mut self,
(edge, extsel): (TriggerMode, ExternalTrigger)
)
pub fn set_external_trigger( &mut self, (edge, extsel): (TriggerMode, ExternalTrigger) )
Sets which external trigger to use and if it is disabled, rising, falling or both
sourcepub fn set_continuous(&mut self, continuous: Continuous)
pub fn set_continuous(&mut self, continuous: Continuous)
Enables and disables continuous mode
sourcepub fn set_end_of_conversion_interrupt(&mut self, eoc: Eoc)
pub fn set_end_of_conversion_interrupt(&mut self, eoc: Eoc)
Sets if the end-of-conversion behaviour. The end-of-conversion interrupt occur either per conversion or for the whole sequence.
sourcepub fn clear_end_of_conversion_flag(&mut self)
pub fn clear_end_of_conversion_flag(&mut self)
Resets the end-of-conversion flag
sourcepub fn set_default_sample_time(&mut self, sample_time: SampleTime)
pub fn set_default_sample_time(&mut self, sample_time: SampleTime)
Sets the default sample time that is used for one-shot conversions.
configure_channel and start_conversion can be
used for configurations where different sampling times are required per channel.
sourcepub fn sequence_length(&mut self) -> u8
pub fn sequence_length(&mut self) -> u8
Returns the current sequence length. Primarily useful for configuring DMA.
sourcepub fn reset_sequence(&mut self)
pub fn reset_sequence(&mut self)
Reset the sequence
sourcepub fn data_register_address(&mut self) -> u32
pub fn data_register_address(&mut self) -> u32
Returns the address of the ADC data register. Primarily useful for configuring DMA.
sourcepub fn configure_channel<CHANNEL>(
&mut self,
_channel: &CHANNEL,
sequence: Sequence,
sample_time: SampleTime
)
pub fn configure_channel<CHANNEL>( &mut self, _channel: &CHANNEL, sequence: Sequence, sample_time: SampleTime )
Configure a channel for sampling.
It will make sure the sequence is at least as long as the sequence
provided.
Arguments
channel
- channel to configuresequence
- where in the sequence to sample the channel. Also called rank in some STM docs/codesample_time
- how long to sample for. See datasheet and ref manual to work out how long you need
to sample for at a given ADC clock frequency
sourcepub fn current_sample(&self) -> u16
pub fn current_sample(&self) -> u16
Returns the current sample stored in the ADC data register
sourcepub fn sample_to_millivolts(&self, sample: u16) -> u16
pub fn sample_to_millivolts(&self, sample: u16) -> u16
Converts a sample value to millivolts using calibrated VDDA and configured resolution. Due to the ADC characteristics VDDA will never be reached as described in #362 and AN2834-How to get the best ADC accuracy in STM32 microcontrollers in section 3.1.2.
sourcepub fn make_sample_to_millivolts(&self) -> impl Fn(u16) -> u16
pub fn make_sample_to_millivolts(&self) -> impl Fn(u16) -> u16
Make a converter for samples to millivolts
sourcepub fn reference_voltage(&self) -> u32
pub fn reference_voltage(&self) -> u32
Returns the VDDA in millivolts calculated from the factory calibration and vrefint. Can be used to get calibration data from ADC1 and use it to configure ADCs that don’t support calibration.
sourcepub fn wait_for_conversion_sequence(&self)
pub fn wait_for_conversion_sequence(&self)
Block until the conversion is completed
Panics
Will panic if there is no conversion started and the end-of-conversion bit is not set
source§impl Adc<ADC3>
impl Adc<ADC3>
sourcepub fn adc3(adc: ADC3, reset: bool, config: AdcConfig) -> Adc<ADC3>
pub fn adc3(adc: ADC3, reset: bool, config: AdcConfig) -> Adc<ADC3>
Enables the ADC clock, resets the peripheral (optionally), runs calibration and applies the supplied config
Arguments
reset
- should a reset be performed. This is provided because on some devices multiple ADCs share the same common reset
sourcepub fn apply_config(&mut self, config: AdcConfig)
pub fn apply_config(&mut self, config: AdcConfig)
Applies all fields in AdcConfig
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns if the adc is enabled
sourcepub fn disable(&mut self)
pub fn disable(&mut self)
Disables the adc
Note
The ADC in the f4 has few restrictions on what can be configured while the ADC is enabled. If any bugs are found where some settings aren’t “sticking” try disabling the ADC before changing them. The reference manual for the chip I’m using only states that the sequence registers are locked when they are being converted.
sourcepub fn start_conversion(&mut self)
pub fn start_conversion(&mut self)
Starts conversion sequence. Waits for the hardware to indicate it’s actually started.
sourcepub fn set_resolution(&mut self, resolution: Resolution)
pub fn set_resolution(&mut self, resolution: Resolution)
Sets the sampling resolution
sourcepub fn set_external_trigger(
&mut self,
(edge, extsel): (TriggerMode, ExternalTrigger)
)
pub fn set_external_trigger( &mut self, (edge, extsel): (TriggerMode, ExternalTrigger) )
Sets which external trigger to use and if it is disabled, rising, falling or both
sourcepub fn set_continuous(&mut self, continuous: Continuous)
pub fn set_continuous(&mut self, continuous: Continuous)
Enables and disables continuous mode
sourcepub fn set_end_of_conversion_interrupt(&mut self, eoc: Eoc)
pub fn set_end_of_conversion_interrupt(&mut self, eoc: Eoc)
Sets if the end-of-conversion behaviour. The end-of-conversion interrupt occur either per conversion or for the whole sequence.
sourcepub fn clear_end_of_conversion_flag(&mut self)
pub fn clear_end_of_conversion_flag(&mut self)
Resets the end-of-conversion flag
sourcepub fn set_default_sample_time(&mut self, sample_time: SampleTime)
pub fn set_default_sample_time(&mut self, sample_time: SampleTime)
Sets the default sample time that is used for one-shot conversions.
configure_channel and start_conversion can be
used for configurations where different sampling times are required per channel.
sourcepub fn sequence_length(&mut self) -> u8
pub fn sequence_length(&mut self) -> u8
Returns the current sequence length. Primarily useful for configuring DMA.
sourcepub fn reset_sequence(&mut self)
pub fn reset_sequence(&mut self)
Reset the sequence
sourcepub fn data_register_address(&mut self) -> u32
pub fn data_register_address(&mut self) -> u32
Returns the address of the ADC data register. Primarily useful for configuring DMA.
sourcepub fn configure_channel<CHANNEL>(
&mut self,
_channel: &CHANNEL,
sequence: Sequence,
sample_time: SampleTime
)
pub fn configure_channel<CHANNEL>( &mut self, _channel: &CHANNEL, sequence: Sequence, sample_time: SampleTime )
Configure a channel for sampling.
It will make sure the sequence is at least as long as the sequence
provided.
Arguments
channel
- channel to configuresequence
- where in the sequence to sample the channel. Also called rank in some STM docs/codesample_time
- how long to sample for. See datasheet and ref manual to work out how long you need
to sample for at a given ADC clock frequency
sourcepub fn current_sample(&self) -> u16
pub fn current_sample(&self) -> u16
Returns the current sample stored in the ADC data register
sourcepub fn sample_to_millivolts(&self, sample: u16) -> u16
pub fn sample_to_millivolts(&self, sample: u16) -> u16
Converts a sample value to millivolts using calibrated VDDA and configured resolution. Due to the ADC characteristics VDDA will never be reached as described in #362 and AN2834-How to get the best ADC accuracy in STM32 microcontrollers in section 3.1.2.
sourcepub fn make_sample_to_millivolts(&self) -> impl Fn(u16) -> u16
pub fn make_sample_to_millivolts(&self) -> impl Fn(u16) -> u16
Make a converter for samples to millivolts
sourcepub fn reference_voltage(&self) -> u32
pub fn reference_voltage(&self) -> u32
Returns the VDDA in millivolts calculated from the factory calibration and vrefint. Can be used to get calibration data from ADC1 and use it to configure ADCs that don’t support calibration.
sourcepub fn wait_for_conversion_sequence(&self)
pub fn wait_for_conversion_sequence(&self)
Block until the conversion is completed
Panics
Will panic if there is no conversion started and the end-of-conversion bit is not set