2021-12-30 09:53:39 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-04-02 02:35:06 +00:00
|
|
|
use defmt::*;
|
2022-08-17 21:40:16 +00:00
|
|
|
use embassy_executor::Spawner;
|
2021-12-30 09:53:39 +00:00
|
|
|
use embassy_stm32::adc::Adc;
|
2022-08-17 21:40:16 +00:00
|
|
|
use embassy_time::{Delay, Duration, Timer};
|
2022-06-12 20:15:44 +00:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2021-12-30 09:53:39 +00:00
|
|
|
|
2022-07-29 19:58:35 +00:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 16:49:55 +00:00
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_stm32::init(Default::default());
|
2021-12-30 09:53:39 +00:00
|
|
|
info!("Hello World!");
|
|
|
|
|
|
|
|
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
|
|
|
let mut pin = p.PB1;
|
|
|
|
|
2022-10-24 20:01:16 +00:00
|
|
|
let mut vrefint = adc.enable_vref(&mut Delay);
|
|
|
|
let vrefint_sample = adc.read(&mut vrefint);
|
2022-10-23 21:31:10 +00:00
|
|
|
let convert_to_millivolts = |sample| {
|
|
|
|
// From http://www.st.com/resource/en/datasheet/CD00161566.pdf
|
|
|
|
// 5.3.4 Embedded reference voltage
|
2022-10-24 20:01:16 +00:00
|
|
|
const VREFINT_MV: u32 = 1200; // mV
|
2022-10-23 21:31:10 +00:00
|
|
|
|
2022-10-24 20:01:16 +00:00
|
|
|
(u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
|
2022-10-23 21:31:10 +00:00
|
|
|
};
|
|
|
|
|
2021-12-30 09:53:39 +00:00
|
|
|
loop {
|
|
|
|
let v = adc.read(&mut pin);
|
2022-10-23 21:31:10 +00:00
|
|
|
info!("--> {} - {} mV", v, convert_to_millivolts(v));
|
2022-01-26 23:08:02 +00:00
|
|
|
Timer::after(Duration::from_millis(100)).await;
|
2021-12-30 09:53:39 +00:00
|
|
|
}
|
|
|
|
}
|