Skip to content

Commit

Permalink
example: add blocking i2c example
Browse files Browse the repository at this point in the history
  • Loading branch information
decaday committed Nov 7, 2024
1 parent 1b9ea25 commit 98615ea
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/py32f030/src/bin/i2c.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![no_std]
#![no_main]
#![feature(impl_trait_in_assoc_type)]

use defmt::*;
use embassy_executor::Spawner;
use py32_hal::i2c::{Error, I2c};
use py32_hal::time::Hertz;
use {defmt_rtt as _, panic_probe as _};

const ADDRESS: u8 = 0x5F;
const WHOAMI: u8 = 0x0F;

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
info!("Hello world!");
let p = py32_hal::init(Default::default());

let mut i2c = I2c::new_blocking(p.I2C1, p.PF1, p.PF0, Hertz(100_000), Default::default());

let mut data = [0u8; 1];

match i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data) {
Ok(()) => info!("Whoami: {}", data[0]),
Err(Error::Timeout) => error!("Operation timed out"),
Err(e) => error!("I2c Error: {:?}", e),
}
}

0 comments on commit 98615ea

Please sign in to comment.