From f9753f3d314ca00fb36103fa39b0911d3e3047ba Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Mon, 21 Jul 2025 14:22:32 +0200 Subject: mspm0: Add I2C Controller examples for mspm0l1306, mspm0g3507 MCUs - mspm0l1306 examples: add I2C blocking & async examples - mspm0l1306 examples: add -O2 optimization due to Flash limitations - mspm0g3507 examples: add I2C blocking & async examples --- examples/mspm0l1306/src/bin/i2c.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/mspm0l1306/src/bin/i2c.rs (limited to 'examples/mspm0l1306/src/bin/i2c.rs') diff --git a/examples/mspm0l1306/src/bin/i2c.rs b/examples/mspm0l1306/src/bin/i2c.rs new file mode 100644 index 000000000..02c0ee740 --- /dev/null +++ b/examples/mspm0l1306/src/bin/i2c.rs @@ -0,0 +1,37 @@ +//! Example of using blocking I2C +//! +//! This uses the virtual COM port provided on the LP-MSPM0L1306 board. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::i2c::{BusSpeed, ClockSel, Config, I2c}; +use {defmt_rtt as _, panic_halt as _}; + +const ADDRESS: u8 = 0x6a; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + let p = embassy_mspm0::init(Default::default()); + + let instance = p.I2C0; + let scl = p.PA1; + let sda = p.PA0; + + let mut config = Config::default(); + config.clock_source = ClockSel::BusClk; + config.bus_speed = BusSpeed::FastMode; + let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, config)); + + let mut to_read = [0u8; 1]; + let to_write: u8 = 0x0F; + + match i2c.blocking_write_read(ADDRESS, &[to_write], &mut to_read) { + Ok(()) => info!("Register {}: {}", to_write, to_read[0]), + Err(e) => error!("I2c Error: {:?}", e), + } + + loop {} +} -- cgit