Adc

Struct Adc 

Source
pub struct Adc<ADC> { /* private fields */ }
Expand description

ADC configuration

Implementations§

Source§

impl<ADC: Instance> Adc<ADC>

Source

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.

Source

pub fn save_cfg(&mut self) -> StoredConfig

Save current ADC config

Source

pub fn restore_cfg(&mut self, cfg: StoredConfig)

Restore saved ADC config

Source

pub fn default_cfg(&mut self) -> StoredConfig

Reset the ADC config to default, return existing config

Source

pub fn set_sample_time(&mut self, t_samp: SampleTime)

Set ADC sampling time

Options can be found in SampleTime.

Source

pub fn set_align(&mut self, align: Align)

Set the Adc result alignment

Options can be found in Align.

Source

pub fn max_sample(&self) -> u16

Returns the largest possible sample value for the current settings

Source

pub fn set_external_trigger(&mut self, trigger: ADC::ExtSel)

Source

pub fn release(self, rcc: &mut RCC) -> ADC

Powers down the ADC, disables the ADC clock and releases the ADC Peripheral

Source

pub fn enable_eoc_interrupt(&mut self)

Enable interrupt for EOC (end of convert)

Source

pub fn disable_eoc_interrupt(&mut self)

Disable interrupt for EOC (end of convert)

Source

pub fn enable_jeoc_interrupt(&mut self)

Enable interrupt for JEOC (EOC for injected channels)

Source

pub fn disable_jeoc_interrupt(&mut self)

Disable interrupt for JEOC (EOC for injected channels)

Source§

impl Adc<ADC1>

Source

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.

Source

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.

Source

pub fn is_temp_vref_enabled(&self) -> bool

Source

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.

Source

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.

Source§

impl Adc<ADC1>

Source

pub fn with_dma<PIN>( self, pins: PIN, dma_ch: C1, ) -> AdcDma<ADC1, PIN, Continuous, C1>
where PIN: Channel<ADC1, ID = u8>,

Source

pub fn with_scan_dma<PINS>( self, pins: PINS, dma_ch: C1, ) -> AdcDma<ADC1, PINS, Scan, C1>
where Self: SetChannels<PINS>,

Source§

impl Adc<ADC3>

Source

pub fn with_dma<PIN>( self, pins: PIN, dma_ch: C5, ) -> AdcDma<ADC3, PIN, Continuous, C5>
where PIN: Channel<ADC3, ID = u8>,

Source

pub fn with_scan_dma<PINS>( self, pins: PINS, dma_ch: C5, ) -> AdcDma<ADC3, PINS, Scan, C5>
where Self: SetChannels<PINS>,

Trait Implementations§

Source§

impl<ADC: Instance> ChannelTimeSequence for Adc<ADC>

Source§

fn set_channel_sample_time(&mut self, chan: u8, sample_time: SampleTime)

Set ADC sampling time for particular channel
Source§

fn set_regular_sequence(&mut self, channels: &[u8])

ADC Set a Regular Channel Conversion Sequence Read more
Source§

fn set_continuous_mode(&mut self, continuous: bool)

Set ADC continuous conversion Read more
Source§

fn set_discontinuous_mode(&mut self, channels: Option<u8>)

Set ADC discontinuous mode Read more
Source§

impl<ADC: Instance, WORD, PIN> OneShot<ADC, WORD, PIN> for Adc<ADC>
where WORD: From<u16>, PIN: Channel<ADC, ID = u8>,

Source§

type Error = ()

Error type returned by ADC methods
Source§

fn read(&mut self, _pin: &mut PIN) -> Result<WORD, Self::Error>

Request that the ADC begin a conversion on the specified pin Read more

Auto Trait Implementations§

§

impl<ADC> Freeze for Adc<ADC>
where ADC: Freeze,

§

impl<ADC> RefUnwindSafe for Adc<ADC>
where ADC: RefUnwindSafe,

§

impl<ADC> Send for Adc<ADC>
where ADC: Send,

§

impl<ADC> Sync for Adc<ADC>
where ADC: Sync,

§

impl<ADC> Unpin for Adc<ADC>
where ADC: Unpin,

§

impl<ADC> UnwindSafe for Adc<ADC>
where ADC: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, const R: u8> RFrom<T, R> for T

Source§

fn rfrom(value: T) -> T

Source§

impl<S, T, const R: u8> RInto<T, R> for S
where T: RFrom<S, R>,

Source§

fn rinto(self) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.