diff options
| author | Frederik <[email protected]> | 2022-02-10 23:21:40 +0100 |
|---|---|---|
| committer | Frederik <[email protected]> | 2022-02-10 23:28:41 +0100 |
| commit | 7a3d28ad0082ca62e806add32c8c0c52a3705b15 (patch) | |
| tree | 82e15062c6eed9628b30ff2d0ae1ce5018054d4f /examples | |
| parent | cbc7f620bd9aa96f2aa4acab232da69f39c4313a (diff) | |
stm32f4: add adc + example
Example tested on stm32f407vg Discovery Board.
minimal adc: no vref, dma, complex sequence
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f4/src/bin/adc.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs new file mode 100644 index 000000000..0a6ddbbca --- /dev/null +++ b/examples/stm32f4/src/bin/adc.rs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | |||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy::time::{Delay, Duration, Timer}; | ||
| 10 | use embassy_stm32::adc::Adc; | ||
| 11 | use embassy_stm32::Peripherals; | ||
| 12 | use example_common::*; | ||
| 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.PC1; | ||
| 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 | } | ||
