embassy/examples/stm32l4/src/bin/adc.rs

45 lines
1.0 KiB
Rust
Raw Normal View History

2021-06-10 21:33:43 +02:00
#![no_std]
#![no_main]
2021-07-03 14:05:12 +02:00
#![allow(incomplete_features)]
2021-06-10 21:33:43 +02:00
#![feature(trait_alias)]
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#[path = "../example_common.rs"]
mod example_common;
2021-07-24 13:57:11 +02:00
use defmt::panic;
use embassy::executor::Spawner;
use embassy::time::Delay;
2021-06-10 21:33:43 +02:00
use embassy_stm32::adc::{Adc, Resolution};
2021-07-24 13:57:11 +02:00
use embassy_stm32::{pac, Peripherals};
use example_common::*;
2021-06-10 21:33:43 +02:00
2021-07-24 13:57:11 +02:00
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
info!("Hello World!");
2021-06-10 21:33:43 +02:00
unsafe {
pac::RCC.ccipr().modify(|w| {
w.set_adcsel(0b11);
});
pac::DBGMCU.cr().modify(|w| {
w.set_dbg_sleep(true);
w.set_dbg_standby(true);
w.set_dbg_stop(true);
});
2021-07-24 13:57:11 +02:00
pac::RCC.ahb2enr().modify(|w| w.set_adcen(true));
}
2021-06-10 21:33:43 +02:00
2021-07-24 13:57:11 +02:00
let mut adc = Adc::new(p.ADC1, &mut Delay);
2021-06-10 21:33:43 +02:00
//adc.enable_vref();
adc.set_resolution(Resolution::EightBit);
let mut channel = p.PC0;
loop {
let v = adc.read(&mut channel);
info!("--> {}", v);
}
}