aboutsummaryrefslogtreecommitdiff
path: root/examples/mspm0g3507/src/bin/i2c.rs
diff options
context:
space:
mode:
authorSiarhei B <[email protected]>2025-07-21 14:22:32 +0200
committerSiarhei B <[email protected]>2025-08-04 10:19:14 +0200
commitf9753f3d314ca00fb36103fa39b0911d3e3047ba (patch)
treee41d14d422fb902587baaa2a8e1ae1516c22168b /examples/mspm0g3507/src/bin/i2c.rs
parent7c640799d66f82f9936f6378cc5dd9856953662e (diff)
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
Diffstat (limited to 'examples/mspm0g3507/src/bin/i2c.rs')
-rw-r--r--examples/mspm0g3507/src/bin/i2c.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/mspm0g3507/src/bin/i2c.rs b/examples/mspm0g3507/src/bin/i2c.rs
new file mode 100644
index 000000000..752649dbc
--- /dev/null
+++ b/examples/mspm0g3507/src/bin/i2c.rs
@@ -0,0 +1,37 @@
1//! Example of using blocking I2C
2//!
3//! This uses the virtual COM port provided on the LP-MSPM0G3507 board.
4
5#![no_std]
6#![no_main]
7
8use defmt::*;
9use embassy_executor::Spawner;
10use embassy_mspm0::i2c::{BusSpeed, ClockSel, Config, I2c};
11use {defmt_rtt as _, panic_halt as _};
12
13const ADDRESS: u8 = 0x6a;
14
15#[embassy_executor::main]
16async fn main(_spawner: Spawner) -> ! {
17 let p = embassy_mspm0::init(Default::default());
18
19 let instance = p.I2C1;
20 let scl = p.PB2;
21 let sda = p.PB3;
22
23 let mut config = Config::default();
24 config.clock_source = ClockSel::BusClk;
25 config.bus_speed = BusSpeed::FastMode;
26 let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, config));
27
28 let mut to_read = [0u8; 1];
29 let to_write: u8 = 0x0F;
30
31 match i2c.blocking_write_read(ADDRESS, &[to_write], &mut to_read) {
32 Ok(()) => info!("Register {}: {}", to_write, to_read[0]),
33 Err(e) => error!("I2c Error: {:?}", e),
34 }
35
36 loop {}
37}