Module stm32f0xx_hal::adc
source · 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::stm32;
use crate::hal::prelude::*;
use crate::hal::adc::Adc;
let mut p = stm32::Peripherals::take().unwrap();
let mut led = gpioa.pa1.into_push_pull_pull_output();
let mut an_in = gpioa.pa0.into_analog();
let rcc = p.RCC.constrain().cfgr.freeze();
let mut delay = Delay::new(cp.SYST, clocks);
let mut adc = Adc::new(p.ADC);
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
methodBattery reference voltage (ADC Channel 18)
Internal voltage reference (ADC Channel 17)
Internal temperature sensor (ADC Channel 16)