aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/stm32f1/src/bin/adc.rs8
-rw-r--r--examples/stm32f4/src/bin/adc.rs12
-rw-r--r--examples/stm32f7/src/bin/adc.rs8
3 files changed, 16 insertions, 12 deletions
diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs
index 3521d06bd..ed59e2799 100644
--- a/examples/stm32f1/src/bin/adc.rs
+++ b/examples/stm32f1/src/bin/adc.rs
@@ -16,14 +16,14 @@ async fn main(_spawner: Spawner) {
16 let mut adc = Adc::new(p.ADC1, &mut Delay); 16 let mut adc = Adc::new(p.ADC1, &mut Delay);
17 let mut pin = p.PB1; 17 let mut pin = p.PB1;
18 18
19 let mut vref = adc.enable_vref(&mut Delay); 19 let mut vrefint = adc.enable_vref(&mut Delay);
20 let vref_sample = adc.read(&mut vref); 20 let vrefint_sample = adc.read(&mut vrefint);
21 let convert_to_millivolts = |sample| { 21 let convert_to_millivolts = |sample| {
22 // From http://www.st.com/resource/en/datasheet/CD00161566.pdf 22 // From http://www.st.com/resource/en/datasheet/CD00161566.pdf
23 // 5.3.4 Embedded reference voltage 23 // 5.3.4 Embedded reference voltage
24 const VREF_MV: u32 = 1200; 24 const VREFINT_MV: u32 = 1200; // mV
25 25
26 (u32::from(sample) * VREF_MV / u32::from(vref_sample)) as u16 26 (u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
27 }; 27 };
28 28
29 loop { 29 loop {
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs
index 5e036bb44..1c9a0b35d 100644
--- a/examples/stm32f4/src/bin/adc.rs
+++ b/examples/stm32f4/src/bin/adc.rs
@@ -24,14 +24,14 @@ 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); 27 let vrefint_sample = adc.read_internal(&mut vrefint);
28 28
29 let convert_to_millivolts = |sample| { 29 let convert_to_millivolts = |sample| {
30 // From http://www.st.com/resource/en/datasheet/DM00071990.pdf 30 // From http://www.st.com/resource/en/datasheet/DM00071990.pdf
31 // 6.3.24 Reference voltage 31 // 6.3.24 Reference voltage
32 const VREF_MILLIVOLTS: u32 = 1210; // mV 32 const VREFINT_MV: u32 = 1210; // mV
33 33
34 (u32::from(sample) * VREF_MILLIVOLTS / u32::from(vref_sample)) as u16 34 (u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
35 }; 35 };
36 36
37 let convert_to_celcius = |sample| { 37 let convert_to_celcius = |sample| {
@@ -45,6 +45,10 @@ async fn main(_spawner: Spawner) {
45 (sample_mv - V25) as f32 / AVG_SLOPE + 25.0 45 (sample_mv - V25) as f32 / AVG_SLOPE + 25.0
46 }; 46 };
47 47
48 info!("VrefInt: {}", vrefint_sample);
49 const MAX_ADC_SAMPLE: u16 = (1 << 12) - 1;
50 info!("VCCA: {} mV", convert_to_millivolts(MAX_ADC_SAMPLE));
51
48 loop { 52 loop {
49 // Read pin 53 // Read pin
50 let v = adc.read(&mut pin); 54 let v = adc.read(&mut pin);
@@ -57,7 +61,7 @@ async fn main(_spawner: Spawner) {
57 61
58 // Read internal voltage reference 62 // Read internal voltage reference
59 let v = adc.read_internal(&mut vrefint); 63 let v = adc.read_internal(&mut vrefint);
60 info!("VrefInt: {} ({} mV)", v, convert_to_millivolts(v)); 64 info!("VrefInt: {}", v);
61 65
62 Timer::after(Duration::from_millis(100)).await; 66 Timer::after(Duration::from_millis(100)).await;
63 } 67 }
diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs
index d932f8b31..70b3b2a75 100644
--- a/examples/stm32f7/src/bin/adc.rs
+++ b/examples/stm32f7/src/bin/adc.rs
@@ -16,14 +16,14 @@ async fn main(_spawner: Spawner) {
16 let mut adc = Adc::new(p.ADC1, &mut Delay); 16 let mut adc = Adc::new(p.ADC1, &mut Delay);
17 let mut pin = p.PA3; 17 let mut pin = p.PA3;
18 18
19 let mut vref = adc.enable_vrefint(); 19 let mut vrefint = adc.enable_vrefint();
20 let vref_sample = adc.read_internal(&mut vref); 20 let vrefint_sample = adc.read_internal(&mut vrefint);
21 let convert_to_millivolts = |sample| { 21 let convert_to_millivolts = |sample| {
22 // From http://www.st.com/resource/en/datasheet/DM00273119.pdf 22 // From http://www.st.com/resource/en/datasheet/DM00273119.pdf
23 // 6.3.27 Reference voltage 23 // 6.3.27 Reference voltage
24 const VREF_MV: u32 = 1210; 24 const VREFINT_MV: u32 = 1210; // mV
25 25
26 (u32::from(sample) * VREF_MV / u32::from(vref_sample)) as u16 26 (u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
27 }; 27 };
28 28
29 loop { 29 loop {