diff options
| author | Matous Hybl <[email protected]> | 2022-05-18 18:34:36 +0200 |
|---|---|---|
| committer | Matous Hybl <[email protected]> | 2022-05-18 18:34:36 +0200 |
| commit | 53f65d8b09c15fcedefd41d721f53ebd296229de (patch) | |
| tree | bef37604fc723817a9f51588823a4bbfafa33f0b /examples/stm32f7 | |
| parent | b7a27113f054de558bd0649ea98462544e9129fb (diff) | |
Automatically set ADC clock prescaler on v2 ADC to respect max frequency
Diffstat (limited to 'examples/stm32f7')
| -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 | } | ||
