From d8ca5614ab7b611b155d16c3a9bd28f29cd48933 Mon Sep 17 00:00:00 2001 From: Connie Date: Fri, 3 May 2024 12:16:46 -0400 Subject: [PATCH] Add ADC --- Cargo.toml | 2 +- src/main.rs | 41 ++++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 54a6a00..24f3112 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ edition = "2021" [dependencies] cortex-m = { version = "0.7.7" } -u5-lib = {git = "ssh://gitea@git.ggeta.com:2002/guangzong/u5_new.git", features = ["utils"], rev= "2f8448f9bf"} +u5-lib = {git = "ssh://gitea@git.ggeta.com:2002/guangzong/u5_new.git", features = ["utils"], rev= "c7bbfd1593"} defmt = "0.3.6" defmt-rtt = { version = "0.4.0" } cortex-m-rt = { version = "0.7.3", default-features = false } diff --git a/src/main.rs b/src/main.rs index 32e9f8a..ea1d86c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,12 +49,11 @@ fn i2c_send( i2c:&mut I2c, addr: u16, mut data: [u8; 2]) { } const POS_DAC_1_ADDR: u16 = 0x20; +const POS_DAC_2_ADDR: u16 = 0x60; +const NEG_DAC_1_ADDR: u16 = 0xA0; +const NEG_DAC_2_ADDR: u16 = 0xE0; const DAC_REG_BASE: u8 = 0xF8; -const DAC_REG_1: u8 = 0xF8; -const DAC_REG_2: u8 = 0xF9; -const DAC_REG_3: u8 = 0xFA; -const DAC_REG_4: u8 = 0xFB; #[task] async fn async_main(spawner: Spawner) { @@ -67,17 +66,33 @@ async fn async_main(spawner: Spawner) { s1.set_low(); s2.set_high(); s3.set_low(); - s4.set_high(); + s4.set_low(); s5.set_low(); - let (mut i2c_plus, mut i2c_minus) = i2c_init(); - for i in 0..4{ - i2c_send(&mut i2c_plus, POS_DAC_1_ADDR, [DAC_REG_BASE + i, 0x50]); - } - for i in 0..4 { - i2c_send(&mut i2c_minus, POS_DAC_1_ADDR, [DAC_REG_BASE + i, 0x50]); - } - defmt::info!("i2c finished!"); + // let (mut i2c_plus, mut i2c_minus) = i2c_init(); + // for i in 0..4{ + // i2c_send(&mut i2c_plus, POS_DAC_1_ADDR, [DAC_REG_BASE + i, 0xA8]); + // } + // for i in 0..4{ + // i2c_send(&mut i2c_plus, POS_DAC_2_ADDR, [DAC_REG_BASE + i, 0xA8]); + // } + // for i in 0..4 { + // i2c_send(&mut i2c_minus, NEG_DAC_1_ADDR, [DAC_REG_BASE + i, 0x50]); + // } + // for i in 0..4 { + // i2c_send(&mut i2c_minus, NEG_DAC_2_ADDR, [DAC_REG_BASE + i, 0x50]); + // } + // defmt::info!("i2c finished!"); + + + let tmp_adc = adc::ADC1; + tmp_adc.init(); + let adc_pin = gpio::ADC1_IN5_PA0; + adc_pin.setup(); + + let res = tmp_adc.start_conversion_sw(5); + defmt::info!("adc value: {}", res); + loop { green.toggle();