diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-05-19 04:00:23 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-19 04:00:23 +0000 |
| commit | 7743b8e1aeb0d00687ceda407ed30d8c69950ed1 (patch) | |
| tree | f8c85363a14425cdf367a89e694b36d182fda64d /examples | |
| parent | 240bef8c9f97998bd4639c714077b7aa59f5e7bc (diff) | |
| parent | 53f65d8b09c15fcedefd41d721f53ebd296229de (diff) | |
Merge #776
776: Automatically set ADC clock prescaler on v2 ADC to respect max frequency r=Dirbaio a=matoushybl
Co-authored-by: Matous Hybl <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f7/src/bin/adc.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs new file mode 100644 index 000000000..87f5d30dd --- /dev/null +++ b/examples/stm32f7/src/bin/adc.rs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt_rtt as _; // global logger | ||
| 6 | use panic_probe as _; | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy::executor::Spawner; | ||
| 10 | use embassy::time::{Delay, Duration, Timer}; | ||
| 11 | use embassy_stm32::adc::Adc; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | let mut adc = Adc::new(p.ADC1, &mut Delay); | ||
| 19 | let mut pin = p.PA3; | ||
| 20 | |||
| 21 | loop { | ||
| 22 | let v = adc.read(&mut pin); | ||
| 23 | info!("--> {} - {} mV", v, adc.to_millivolts(v)); | ||
| 24 | Timer::after(Duration::from_millis(100)).await; | ||
| 25 | } | ||
| 26 | } | ||
