mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 14:22:33 +00:00
stm32: update adc examples
This commit is contained in:
parent
68b1a840c6
commit
fd901fc7e0
@ -6,7 +6,7 @@ use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::{Adc, SampleTime};
|
||||
use embassy_stm32::peripherals::ADC;
|
||||
use embassy_stm32::{adc, bind_interrupts};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@ -18,11 +18,11 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let mut adc = Adc::new(p.ADC, Irqs, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC, Irqs);
|
||||
adc.set_sample_time(SampleTime::CYCLES71_5);
|
||||
let mut pin = p.PA1;
|
||||
|
||||
let mut vrefint = adc.enable_vref(&mut Delay);
|
||||
let mut vrefint = adc.enable_vref();
|
||||
let vrefint_sample = adc.read(&mut vrefint).await;
|
||||
let convert_to_millivolts = |sample| {
|
||||
// From https://www.st.com/resource/en/datasheet/stm32f031c6.pdf
|
||||
|
@ -6,7 +6,7 @@ use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::Adc;
|
||||
use embassy_stm32::peripherals::ADC1;
|
||||
use embassy_stm32::{adc, bind_interrupts};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@ -18,10 +18,10 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC1);
|
||||
let mut pin = p.PB1;
|
||||
|
||||
let mut vrefint = adc.enable_vref(&mut Delay);
|
||||
let mut vrefint = adc.enable_vref();
|
||||
let vrefint_sample = adc.read(&mut vrefint).await;
|
||||
let convert_to_millivolts = |sample| {
|
||||
// From http://www.st.com/resource/en/datasheet/CD00161566.pdf
|
||||
|
@ -7,7 +7,7 @@ use embassy_stm32::adc::{Adc, SampleTime};
|
||||
use embassy_stm32::peripherals::ADC1;
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{adc, bind_interrupts, Config};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@ -38,13 +38,13 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
|
||||
info!("create adc...");
|
||||
|
||||
let mut adc = Adc::new(p.ADC1, Irqs, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC1, Irqs);
|
||||
|
||||
adc.set_sample_time(SampleTime::CYCLES601_5);
|
||||
|
||||
info!("enable vrefint...");
|
||||
|
||||
let mut vrefint = adc.enable_vref(&mut Delay);
|
||||
let mut vrefint = adc.enable_vref();
|
||||
let mut temperature = adc.enable_temperature();
|
||||
|
||||
loop {
|
||||
|
@ -8,7 +8,7 @@ use embassy_stm32::opamp::{OpAmp, OpAmpGain};
|
||||
use embassy_stm32::peripherals::ADC2;
|
||||
use embassy_stm32::time::mhz;
|
||||
use embassy_stm32::{adc, bind_interrupts, Config};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@ -39,14 +39,14 @@ async fn main(_spawner: Spawner) -> ! {
|
||||
|
||||
info!("create adc...");
|
||||
|
||||
let mut adc = Adc::new(p.ADC2, Irqs, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC2, Irqs);
|
||||
let mut opamp = OpAmp::new(p.OPAMP2);
|
||||
|
||||
adc.set_sample_time(SampleTime::CYCLES601_5);
|
||||
|
||||
info!("enable vrefint...");
|
||||
|
||||
let mut vrefint = adc.enable_vref(&mut Delay);
|
||||
let mut vrefint = adc.enable_vref();
|
||||
let mut temperature = adc.enable_temperature();
|
||||
let mut buffer = opamp.buffer_ext(&mut p.PA7, &mut p.PA6, OpAmpGain::Mul1);
|
||||
|
||||
|
@ -14,7 +14,7 @@ async fn main(_spawner: Spawner) {
|
||||
info!("Hello World!");
|
||||
|
||||
let mut delay = Delay;
|
||||
let mut adc = Adc::new(p.ADC1, &mut delay);
|
||||
let mut adc = Adc::new(p.ADC1);
|
||||
let mut pin = p.PC1;
|
||||
|
||||
let mut vrefint = adc.enable_vrefint();
|
||||
|
@ -4,7 +4,7 @@
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::Adc;
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
@ -12,7 +12,7 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC1);
|
||||
let mut pin = p.PA3;
|
||||
|
||||
let mut vrefint = adc.enable_vrefint();
|
||||
|
@ -5,7 +5,7 @@ use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::{Adc, SampleTime};
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
@ -28,7 +28,7 @@ async fn main(_spawner: Spawner) {
|
||||
let mut p = embassy_stm32::init(config);
|
||||
info!("Hello World!");
|
||||
|
||||
let mut adc = Adc::new(p.ADC2, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC2);
|
||||
adc.set_sample_time(SampleTime::CYCLES32_5);
|
||||
|
||||
loop {
|
||||
|
@ -5,7 +5,7 @@ use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::{Adc, SampleTime};
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
@ -44,7 +44,7 @@ async fn main(_spawner: Spawner) {
|
||||
|
||||
info!("Hello World!");
|
||||
|
||||
let mut adc = Adc::new(p.ADC3, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC3);
|
||||
|
||||
adc.set_sample_time(SampleTime::CYCLES32_5);
|
||||
|
||||
|
@ -6,7 +6,7 @@ use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::{Adc, SampleTime};
|
||||
use embassy_stm32::peripherals::ADC;
|
||||
use embassy_stm32::{adc, bind_interrupts};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@ -18,11 +18,11 @@ async fn main(_spawner: Spawner) {
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
info!("Hello World!");
|
||||
|
||||
let mut adc = Adc::new(p.ADC, Irqs, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC, Irqs);
|
||||
adc.set_sample_time(SampleTime::CYCLES79_5);
|
||||
let mut pin = p.PA1;
|
||||
|
||||
let mut vrefint = adc.enable_vref(&mut Delay);
|
||||
let mut vrefint = adc.enable_vref();
|
||||
let vrefint_sample = adc.read(&mut vrefint).await;
|
||||
let convert_to_millivolts = |sample| {
|
||||
// From https://www.st.com/resource/en/datasheet/stm32l051c6.pdf
|
||||
|
@ -4,7 +4,6 @@
|
||||
use defmt::*;
|
||||
use embassy_stm32::adc::{Adc, Resolution};
|
||||
use embassy_stm32::Config;
|
||||
use embassy_time::Delay;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
@ -18,7 +17,7 @@ fn main() -> ! {
|
||||
}
|
||||
let p = embassy_stm32::init(config);
|
||||
|
||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||
let mut adc = Adc::new(p.ADC1);
|
||||
//adc.enable_vref();
|
||||
adc.set_resolution(Resolution::BITS8);
|
||||
let mut channel = p.PC0;
|
||||
|
@ -13,7 +13,7 @@ use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::Adc;
|
||||
use embassy_stm32::dac::{DacCh1, Value};
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Timer;
|
||||
use micromath::F32Ext;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
@ -28,7 +28,7 @@ async fn main(_spawner: Spawner) {
|
||||
let mut adc_pin = unsafe { core::ptr::read(&dac_pin) };
|
||||
|
||||
let mut dac = DacCh1::new(dac, NoDma, dac_pin);
|
||||
let mut adc = Adc::new(adc, &mut Delay);
|
||||
let mut adc = Adc::new(adc);
|
||||
|
||||
#[cfg(feature = "stm32h755zi")]
|
||||
let normalization_factor = 256;
|
||||
|
Loading…
Reference in New Issue
Block a user