diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-10-26 19:44:06 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-10-26 19:44:06 +0000 |
| commit | 7f499f3edcd0f1f3e32c0d624737c5dbede45f9a (patch) | |
| tree | 8c12e0fc4384372ecba5491e895fb8d3f4fce577 /examples/stm32f7 | |
| parent | 01e23bf9dd2f7d55a01d5a0ac18bc6f26ca05e30 (diff) | |
| parent | 7a6732adcfd09d72f5335f85cbe4e263234849e7 (diff) | |
Merge #1024
1024: stm32/adc: Remove voltage and temperature conversions r=Dirbaio a=GrantM11235
The current conversion utilities are confusing and a bit of a footgun. (Two out of the three examples got it wrong! They didn't measure vref at all, so all the conversions are completely wrong if vcca isn't 3.3v)
I think we should eventually have some sort of conversion utilities in the HAL, but for now I think it is best to just remove it and let the users do their own math.
cc `@chemicstry`
Co-authored-by: Grant Miller <[email protected]>
Diffstat (limited to 'examples/stm32f7')
| -rw-r--r-- | examples/stm32f7/src/bin/adc.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs index 80fad8c41..70b3b2a75 100644 --- a/examples/stm32f7/src/bin/adc.rs +++ b/examples/stm32f7/src/bin/adc.rs | |||
| @@ -16,9 +16,19 @@ 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 vrefint = adc.enable_vrefint(); | ||
| 20 | let vrefint_sample = adc.read_internal(&mut vrefint); | ||
| 21 | let convert_to_millivolts = |sample| { | ||
| 22 | // From http://www.st.com/resource/en/datasheet/DM00273119.pdf | ||
| 23 | // 6.3.27 Reference voltage | ||
| 24 | const VREFINT_MV: u32 = 1210; // mV | ||
| 25 | |||
| 26 | (u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16 | ||
| 27 | }; | ||
| 28 | |||
| 19 | loop { | 29 | loop { |
| 20 | let v = adc.read(&mut pin); | 30 | let v = adc.read(&mut pin); |
| 21 | info!("--> {} - {} mV", v, adc.to_millivolts(v)); | 31 | info!("--> {} - {} mV", v, convert_to_millivolts(v)); |
| 22 | Timer::after(Duration::from_millis(100)).await; | 32 | Timer::after(Duration::from_millis(100)).await; |
| 23 | } | 33 | } |
| 24 | } | 34 | } |
