aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src
diff options
context:
space:
mode:
authorGrant Miller <[email protected]>2022-10-23 16:31:10 -0500
committerGrant Miller <[email protected]>2022-10-24 04:00:29 -0500
commit545cc9326b47efc27549a60b3539e93ea0d04d70 (patch)
tree275a01869a94a07c513d90795633cbde44b4fe1e /examples/stm32f4/src
parentce1cba761c2942b7faa27f4098487c6468784729 (diff)
stm32/adc: Remove voltage and temperature conversions
Diffstat (limited to 'examples/stm32f4/src')
-rw-r--r--examples/stm32f4/src/bin/adc.rs27
1 files changed, 24 insertions, 3 deletions
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs
index 1d030f7dc..5e036bb44 100644
--- a/examples/stm32f4/src/bin/adc.rs
+++ b/examples/stm32f4/src/bin/adc.rs
@@ -24,19 +24,40 @@ async fn main(_spawner: Spawner) {
24 // Startup delay can be combined to the maximum of either 24 // Startup delay can be combined to the maximum of either
25 delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us())); 25 delay.delay_us(Temperature::start_time_us().max(VrefInt::start_time_us()));
26 26
27 let vref_sample = adc.read_internal(&mut vrefint);
28
29 let convert_to_millivolts = |sample| {
30 // From http://www.st.com/resource/en/datasheet/DM00071990.pdf
31 // 6.3.24 Reference voltage
32 const VREF_MILLIVOLTS: u32 = 1210; // mV
33
34 (u32::from(sample) * VREF_MILLIVOLTS / u32::from(vref_sample)) as u16
35 };
36
37 let convert_to_celcius = |sample| {
38 // From http://www.st.com/resource/en/datasheet/DM00071990.pdf
39 // 6.3.22 Temperature sensor characteristics
40 const V25: i32 = 760; // mV
41 const AVG_SLOPE: f32 = 2.5; // mV/C
42
43 let sample_mv = convert_to_millivolts(sample) as i32;
44
45 (sample_mv - V25) as f32 / AVG_SLOPE + 25.0
46 };
47
27 loop { 48 loop {
28 // Read pin 49 // Read pin
29 let v = adc.read(&mut pin); 50 let v = adc.read(&mut pin);
30 info!("PC1: {} ({} mV)", v, adc.to_millivolts(v)); 51 info!("PC1: {} ({} mV)", v, convert_to_millivolts(v));
31 52
32 // Read internal temperature 53 // Read internal temperature
33 let v = adc.read_internal(&mut temp); 54 let v = adc.read_internal(&mut temp);
34 let celcius = Temperature::to_celcius(adc.to_millivolts(v)); 55 let celcius = convert_to_celcius(v);
35 info!("Internal temp: {} ({} C)", v, celcius); 56 info!("Internal temp: {} ({} C)", v, celcius);
36 57
37 // Read internal voltage reference 58 // Read internal voltage reference
38 let v = adc.read_internal(&mut vrefint); 59 let v = adc.read_internal(&mut vrefint);
39 info!("VrefInt: {} ({} mV)", v, adc.to_millivolts(v)); 60 info!("VrefInt: {} ({} mV)", v, convert_to_millivolts(v));
40 61
41 Timer::after(Duration::from_millis(100)).await; 62 Timer::after(Duration::from_millis(100)).await;
42 } 63 }