Merge #563
563: Initial ADC support for on STM32F1xx r=Dirbaio a=sjoerdsimons Add an ADC implementation for F1 based chips. Primarily tested using ADC1, proper functionality for ADC2 probably needs some extra work as it's mainly a slave and can't e.g. measure vrefint by itself. Needs https://github.com/embassy-rs/stm32-data/pull/115 Co-authored-by: Sjoerd Simons <sjoerd@collabora.com> Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
@ -20,3 +20,6 @@ panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
|
||||
heapless = { version = "0.7.5", default-features = false }
|
||||
nb = "1.0.0"
|
||||
|
||||
[profile.dev]
|
||||
opt-level = "s"
|
||||
|
29
examples/stm32f1/src/bin/adc.rs
Normal file
29
examples/stm32f1/src/bin/adc.rs
Normal file
@ -0,0 +1,29 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::Delay;
|
||||
use embassy_stm32::adc::Adc;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::delay::Delay as _;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello World!");
|
||||
|
||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||
let mut pin = p.PB1;
|
||||
|
||||
let mut vref = adc.enable_vref(&mut Delay);
|
||||
adc.calibrate(&mut vref);
|
||||
loop {
|
||||
let v = adc.read(&mut pin);
|
||||
info!("--> {} - {} mV", v, adc.to_millivolts(v));
|
||||
Delay.delay_ms(100).await;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user