diff options
author | Sjoerd Simons <sjoerd@collabora.com> | 2021-12-30 10:53:39 +0100 |
---|---|---|
committer | Sjoerd Simons <sjoerd@collabora.com> | 2021-12-30 10:53:39 +0100 |
commit | dafc4c54e98422a87a1f7b46edfca2736cfe116d (patch) | |
tree | 0972dc62ba428660b7e8ac5d323cd5931a007388 /examples/stm32f1 | |
parent | f0f08f298bc7fd8b60685d3cc11a02a3829b650b (diff) | |
download | embassy-dafc4c54e98422a87a1f7b46edfca2736cfe116d.zip |
examples: stm32f1: Add an example of using the ADC
Diffstat (limited to 'examples/stm32f1')
-rw-r--r-- | examples/stm32f1/src/bin/adc.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs new file mode 100644 index 00000000..de221463 --- /dev/null +++ b/examples/stm32f1/src/bin/adc.rs @@ -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; + } +} |