diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f334/src/bin/adc.rs | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/examples/stm32f334/src/bin/adc.rs b/examples/stm32f334/src/bin/adc.rs index 729497e82..6dffd6731 100644 --- a/examples/stm32f334/src/bin/adc.rs +++ b/examples/stm32f334/src/bin/adc.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | use defmt::info; | 5 | use defmt::info; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::adc::Adc; | 7 | use embassy_stm32::adc::{Adc, VREF_INT}; |
| 8 | use embassy_stm32::rcc::{ADCClock, ADCPrescaler}; | 8 | use embassy_stm32::rcc::{ADCClock, ADCPrescaler}; |
| 9 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 10 | use embassy_stm32::Config; | 10 | use embassy_stm32::Config; |
| @@ -20,15 +20,28 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 20 | 20 | ||
| 21 | let mut p = embassy_stm32::init(config); | 21 | let mut p = embassy_stm32::init(config); |
| 22 | 22 | ||
| 23 | info!("create adc..."); | ||
| 24 | |||
| 23 | let mut adc = Adc::new(p.ADC1, &mut Delay); | 25 | let mut adc = Adc::new(p.ADC1, &mut Delay); |
| 24 | 26 | ||
| 25 | let mut vrefint = adc.enable_vref(&mut Delay); | 27 | info!("enable vrefint..."); |
| 26 | 28 | ||
| 27 | let _vref = adc.read(&mut vrefint); | 29 | let mut vrefint = adc.enable_vref(&mut Delay); |
| 28 | let _pin = adc.read(&mut p.PA0); | 30 | let mut temperature = adc.enable_temperature(); |
| 29 | 31 | ||
| 30 | loop { | 32 | loop { |
| 31 | info!("Hello World!"); | 33 | let vref = adc.read(&mut vrefint); |
| 34 | info!("read vref: {}", vref); | ||
| 35 | |||
| 36 | let temp = adc.read(&mut temperature); | ||
| 37 | info!("read temperature: {}", temp); | ||
| 38 | |||
| 39 | let pin = adc.read(&mut p.PA0); | ||
| 40 | info!("read pin: {}", pin); | ||
| 41 | |||
| 42 | let pin_mv = pin as u32 * VREF_INT as u32 / vref as u32; | ||
| 43 | info!("computed pin mv: {}", pin_mv); | ||
| 44 | |||
| 32 | Timer::after(Duration::from_secs(1)).await; | 45 | Timer::after(Duration::from_secs(1)).await; |
| 33 | } | 46 | } |
| 34 | } | 47 | } |
