From 8c3f7c70cc48f9017b2148a6aa9674ce21e3ff95 Mon Sep 17 00:00:00 2001 From: Frederik Menke Date: Sat, 20 Jul 2024 16:52:28 +0200 Subject: [PATCH] Set up communication with sensor --- src/main.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 457566f..895ee74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,6 @@ use {defmt_rtt as _, panic_probe as _}; use embassy_rp::i2c::{self, Config}; use embassy_time::{Duration, Timer}; -use embedded_hal_async::i2c::I2c; bind_interrupts!(struct Irqs { I2C1_IRQ => i2c::InterruptHandler; @@ -30,6 +29,11 @@ bind_interrupts!(struct Irqs { struct DummyTimesource(); +/// I2C Address of the co2 sensor +const CCS811_I2C_ADDRESS: u16 = 0x5A; +/// I2C Register addresses of the co2 sensor +const CCS811_REGISTER_STATUS: u8 = 0x00; + impl embedded_sdmmc::TimeSource for DummyTimesource { fn get_timestamp(&self) -> embedded_sdmmc::Timestamp { embedded_sdmmc::Timestamp { @@ -52,12 +56,30 @@ async fn main(spawner: Spawner) { // .spawn(write_to_sd(p.SPI1, p.PIN_10, p.PIN_11, p.PIN_12, p.PIN_16)) // .unwrap(); + // Wake pin is not required as long as its kept low at all times + // let mut nWAKE = gpio::Output::new(p.PIN_13, Level::High); + let sda = p.PIN_14; let scl = p.PIN_15; info!("set up i2c "); let mut i2c = embassy_rp::i2c::I2c::new_async(p.I2C1, scl, sda, Irqs, Config::default()); + // Wait for sensor to boot + Timer::after(Duration::from_secs(1)).await; + + debug!("Writing to I2C"); + let mut status = [42]; + i2c.write_async(CCS811_I2C_ADDRESS, [CCS811_REGISTER_STATUS]) + .await + .unwrap(); + debug!("Reading from I2C"); + i2c.read_async(CCS811_I2C_ADDRESS, &mut status) + .await + .unwrap(); + + info!("Reported status: {}", status); + debug!("TASK ENDED: Main") }