Set up communication with sensor
This commit is contained in:
parent
992ae640a6
commit
8c3f7c70cc
24
src/main.rs
24
src/main.rs
|
@ -22,7 +22,6 @@ use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
use embassy_rp::i2c::{self, Config};
|
use embassy_rp::i2c::{self, Config};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
use embedded_hal_async::i2c::I2c;
|
|
||||||
|
|
||||||
bind_interrupts!(struct Irqs {
|
bind_interrupts!(struct Irqs {
|
||||||
I2C1_IRQ => i2c::InterruptHandler<embassy_rp::peripherals::I2C1>;
|
I2C1_IRQ => i2c::InterruptHandler<embassy_rp::peripherals::I2C1>;
|
||||||
|
@ -30,6 +29,11 @@ bind_interrupts!(struct Irqs {
|
||||||
|
|
||||||
struct DummyTimesource();
|
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 {
|
impl embedded_sdmmc::TimeSource for DummyTimesource {
|
||||||
fn get_timestamp(&self) -> embedded_sdmmc::Timestamp {
|
fn get_timestamp(&self) -> embedded_sdmmc::Timestamp {
|
||||||
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))
|
// .spawn(write_to_sd(p.SPI1, p.PIN_10, p.PIN_11, p.PIN_12, p.PIN_16))
|
||||||
// .unwrap();
|
// .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 sda = p.PIN_14;
|
||||||
let scl = p.PIN_15;
|
let scl = p.PIN_15;
|
||||||
|
|
||||||
info!("set up i2c ");
|
info!("set up i2c ");
|
||||||
let mut i2c = embassy_rp::i2c::I2c::new_async(p.I2C1, scl, sda, Irqs, Config::default());
|
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")
|
debug!("TASK ENDED: Main")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue