Module stm32f0xx_hal::adc[][src]

Expand description

API for the Analog to Digital converter

Currently implements oneshot conversion with variable sampling times. Also references for the internal temperature sense, voltage reference and battery sense are provided.

Example

use stm32f0xx_hal as hal;

use crate::hal::pac;
use crate::hal::prelude::*;
use crate::hal::adc::Adc;

cortex_m::interrupt::free(|cs| {
    let mut p = pac::Peripherals::take().unwrap();
    let mut rcc = p.RCC.configure().freeze(&mut p.FLASH);

    let gpioa = p.GPIOA.split(&mut rcc);

    let mut led = gpioa.pa1.into_push_pull_pull_output(cs);
    let mut an_in = gpioa.pa0.into_analog(cs);

    let mut delay = Delay::new(cp.SYST, &rcc);

    let mut adc = Adc::new(p.ADC, &mut rcc);

    loop {
        let val: u16 = adc.read(&mut an_in).unwrap();
        if val < ((1 << 8) - 1) {
            led.set_low();
        } else {
            led.set_high();
        }
        delay.delay_ms(50_u16);
    }
});

Structs

Analog to Digital converter interface

A stored ADC config, can be restored by using the Adc::restore_cfg method

Battery reference voltage (ADC Channel 18)

Internal voltage reference (ADC Channel 17)

Internal temperature sensor (ADC Channel 16)

Enums

ADC Result Alignment

ADC Sampling Precision

ADC Sampling time