diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-13 11:44:59 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-13 11:44:59 +0000 |
| commit | eb922c4655db4b22acf808855e3bc003d3b8ba89 (patch) | |
| tree | 996cc09254953299cb310285bf05195774be5441 /examples/stm32f4 | |
| parent | b74ccf2d348e9bba1e201e196381f772197e3257 (diff) | |
| parent | 7a3d34c1ed3db330c6db55b81cd535747181c3cb (diff) | |
Merge #608
608: stm32f4: add adc + example r=Dirbaio a=ain101
Example tested on stm32f407vg Discovery Board.
minimal adc: no vref, dma, complex sequence
Co-authored-by: Frederik <[email protected]>
Diffstat (limited to 'examples/stm32f4')
| -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 | } | ||
