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 <GrantM11235@gmail.com>
This commit is contained in:
@ -16,9 +16,19 @@ async fn main(_spawner: Spawner) {
|
||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||
let mut pin = p.PA3;
|
||||
|
||||
let mut vrefint = adc.enable_vrefint();
|
||||
let vrefint_sample = adc.read_internal(&mut vrefint);
|
||||
let convert_to_millivolts = |sample| {
|
||||
// From http://www.st.com/resource/en/datasheet/DM00273119.pdf
|
||||
// 6.3.27 Reference voltage
|
||||
const VREFINT_MV: u32 = 1210; // mV
|
||||
|
||||
(u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
|
||||
};
|
||||
|
||||
loop {
|
||||
let v = adc.read(&mut pin);
|
||||
info!("--> {} - {} mV", v, adc.to_millivolts(v));
|
||||
info!("--> {} - {} mV", v, convert_to_millivolts(v));
|
||||
Timer::after(Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user