aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-10-10 06:28:41 +0000
committerGitHub <[email protected]>2022-10-10 06:28:41 +0000
commitef533e6df48d35b57fcb497e7bb5d6bafd6ca725 (patch)
tree44d6dfa425e60deb6dd28eb738563b5857d75719 /examples
parentf8fd6ab208fd09142ab9789078e9b23ba8c3e6a9 (diff)
parent322cfafed353ddfbe62121238ef97c56dd7a6eed (diff)
Merge #1004
1004: Fix internal channels for adc v2 r=lulf a=chemicstry Internal channel reading was broken on adc_v2, because `Adc::read()` requires gpio pin trait, which was not implemented by `VrefInt`, `Temperature`, `Vbat`. The required configuration bits `tsvrefe`, `vbate` were not enabled either. This PR makes it a bit closer to how adc_v4 works. While at it, I also changed adc_v2 to use `RccPeripheral` instead of permanently enabling all ADCs. Co-authored-by: chemicstry <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f4/src/bin/adc.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs
index 871185074..1d030f7dc 100644
--- a/examples/stm32f4/src/bin/adc.rs
+++ b/examples/stm32f4/src/bin/adc.rs
@@ -2,9 +2,10 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use cortex_m::prelude::_embedded_hal_blocking_delay_DelayUs;
5use defmt::*; 6use defmt::*;
6use embassy_executor::Spawner; 7use embassy_executor::Spawner;
7use embassy_stm32::adc::Adc; 8use embassy_stm32::adc::{Adc, Temperature, VrefInt};
8use embassy_time::{Delay, Duration, Timer}; 9use embassy_time::{Delay, Duration, Timer};
9use {defmt_rtt as _, panic_probe as _}; 10use {defmt_rtt as _, panic_probe as _};
10 11
@@ -13,12 +14,30 @@ async fn main(_spawner: Spawner) {
13 let p = embassy_stm32::init(Default::default()); 14 let p = embassy_stm32::init(Default::default());
14 info!("Hello World!"); 15 info!("Hello World!");
15 16
16 let mut adc = Adc::new(p.ADC1, &mut Delay); 17 let mut delay = Delay;
18 let mut adc = Adc::new(p.ADC1, &mut delay);
17 let mut pin = p.PC1; 19 let mut pin = p.PC1;
18 20
21 let mut vrefint = adc.enable_vrefint();
22 let mut temp = adc.enable_temperature();
23
24 // Startup delay can be combined to the maximum of either
25 delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us()));
26
19 loop { 27 loop {
28 // Read pin
20 let v = adc.read(&mut pin); 29 let v = adc.read(&mut pin);
21 info!("--> {} - {} mV", v, adc.to_millivolts(v)); 30 info!("PC1: {} ({} mV)", v, adc.to_millivolts(v));
31
32 // Read internal temperature
33 let v = adc.read_internal(&mut temp);
34 let celcius = Temperature::to_celcius(adc.to_millivolts(v));
35 info!("Internal temp: {} ({} C)", v, celcius);
36
37 // Read internal voltage reference
38 let v = adc.read_internal(&mut vrefint);
39 info!("VrefInt: {} ({} mV)", v, adc.to_millivolts(v));
40
22 Timer::after(Duration::from_millis(100)).await; 41 Timer::after(Duration::from_millis(100)).await;
23 } 42 }
24} 43}