aboutsummaryrefslogtreecommitdiff
path: root/examples/mspm0l1306/src/bin/i2c_async.rs
diff options
context:
space:
mode:
author1-rafael-1 <[email protected]>2025-09-15 20:07:18 +0200
committer1-rafael-1 <[email protected]>2025-09-15 20:07:18 +0200
commit6bb3d2c0720fa082f27d3cdb70f516058497ec87 (patch)
tree5a1e255cff999b00800f203b91a759c720c973e5 /examples/mspm0l1306/src/bin/i2c_async.rs
parenteb685574601d98c44faed9a3534d056199b46e20 (diff)
parent92a6fd2946f2cbb15359290f68aa360953da2ff7 (diff)
Merge branch 'main' into rp2040-rtc-alarm
Diffstat (limited to 'examples/mspm0l1306/src/bin/i2c_async.rs')
-rw-r--r--examples/mspm0l1306/src/bin/i2c_async.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/mspm0l1306/src/bin/i2c_async.rs b/examples/mspm0l1306/src/bin/i2c_async.rs
new file mode 100644
index 000000000..c4a6938ff
--- /dev/null
+++ b/examples/mspm0l1306/src/bin/i2c_async.rs
@@ -0,0 +1,50 @@
1//! The example uses FIFO and interrupts, wrapped in async API.
2//!
3//! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0L1306 board.
4
5#![no_std]
6#![no_main]
7
8use defmt::*;
9use embassy_executor::Spawner;
10use embassy_mspm0::bind_interrupts;
11use embassy_mspm0::i2c::{Config, I2c, InterruptHandler};
12use embassy_mspm0::peripherals::I2C0;
13use embassy_time::Timer;
14use {defmt_rtt as _, panic_halt as _};
15
16const ADDRESS: u8 = 0x6a;
17
18bind_interrupts!(struct Irqs {
19 I2C0 => InterruptHandler<I2C0>;
20});
21
22#[embassy_executor::main]
23async fn main(_spawner: Spawner) -> ! {
24 let p = embassy_mspm0::init(Default::default());
25
26 let instance = p.I2C0;
27 let scl = p.PA1;
28 let sda = p.PA0;
29
30 let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, Config::default()));
31
32 let mut pot_value: u8 = 0;
33
34 loop {
35 let to_write = [0u8, pot_value];
36
37 match i2c.async_write(ADDRESS, &to_write).await {
38 Ok(()) => info!("New potentioemter value: {}", pot_value),
39 Err(e) => error!("I2c Error: {:?}", e),
40 }
41
42 pot_value += 1;
43 // if reached 64th position (max)
44 // start over from lowest value
45 if pot_value == 64 {
46 pot_value = 0;
47 }
48 Timer::after_millis(500).await;
49 }
50}