aboutsummaryrefslogtreecommitdiff
path: root/examples/mspm0g3507/src
diff options
context:
space:
mode:
authorSiarhei B <[email protected]>2025-08-04 13:10:39 +0200
committerSiarhei B <[email protected]>2025-08-04 13:10:39 +0200
commite78959ed67f8c89f2adc78f5e4580c62d3c66081 (patch)
tree1d3d9eba5680ae1cc2b49e0c0981d003f1d17512 /examples/mspm0g3507/src
parent3b7b343863ac347bf86f4d2a79cb43788b5fcdc0 (diff)
mspm0-I2C: replace examples for mspm0l1306 & mspm0g3507 with AD5171
Diffstat (limited to 'examples/mspm0g3507/src')
-rw-r--r--examples/mspm0g3507/src/bin/i2c.rs26
-rw-r--r--examples/mspm0g3507/src/bin/i2c_async.rs26
2 files changed, 36 insertions, 16 deletions
diff --git a/examples/mspm0g3507/src/bin/i2c.rs b/examples/mspm0g3507/src/bin/i2c.rs
index 2e3bf2ca1..8d1ed1726 100644
--- a/examples/mspm0g3507/src/bin/i2c.rs
+++ b/examples/mspm0g3507/src/bin/i2c.rs
@@ -1,7 +1,7 @@
1//! This example uses FIFO with polling, and the maximum FIFO size is 8. 1//! This example uses FIFO with polling, and the maximum FIFO size is 8.
2//! Refer to async example to handle larger packets. 2//! Refer to async example to handle larger packets.
3//! 3//!
4//! This uses the virtual COM port provided on the LP-MSPM0G3507 board. 4//! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0G3507 board.
5 5
6#![no_std] 6#![no_std]
7#![no_main] 7#![no_main]
@@ -9,6 +9,7 @@
9use defmt::*; 9use defmt::*;
10use embassy_executor::Spawner; 10use embassy_executor::Spawner;
11use embassy_mspm0::i2c::{Config, I2c}; 11use embassy_mspm0::i2c::{Config, I2c};
12use embassy_time::Timer;
12use {defmt_rtt as _, panic_halt as _}; 13use {defmt_rtt as _, panic_halt as _};
13 14
14const ADDRESS: u8 = 0x6a; 15const ADDRESS: u8 = 0x6a;
@@ -23,13 +24,22 @@ async fn main(_spawner: Spawner) -> ! {
23 24
24 let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, Config::default())); 25 let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, Config::default()));
25 26
26 let mut to_read = [0u8; 1]; 27 let mut pot_value: u8 = 0;
27 let to_write: u8 = 0x0F;
28 28
29 match i2c.blocking_write_read(ADDRESS, &[to_write], &mut to_read) { 29 loop {
30 Ok(()) => info!("Register {}: {}", to_write, to_read[0]), 30 let to_write = [0u8, pot_value];
31 Err(e) => error!("I2c Error: {:?}", e), 31
32 } 32 match i2c.blocking_write(ADDRESS, &to_write) {
33 Ok(()) => info!("New potentioemter value: {}", pot_value),
34 Err(e) => error!("I2c Error: {:?}", e),
35 }
33 36
34 loop {} 37 pot_value += 1;
38 // if reached 64th position (max)
39 // start over from lowest value
40 if pot_value == 64 {
41 pot_value = 0;
42 }
43 Timer::after_millis(500).await;
44 }
35} 45}
diff --git a/examples/mspm0g3507/src/bin/i2c_async.rs b/examples/mspm0g3507/src/bin/i2c_async.rs
index 294550605..d486e2a03 100644
--- a/examples/mspm0g3507/src/bin/i2c_async.rs
+++ b/examples/mspm0g3507/src/bin/i2c_async.rs
@@ -1,6 +1,6 @@
1//! The example uses FIFO and interrupts, wrapped in async API. 1//! The example uses FIFO and interrupts, wrapped in async API.
2//! 2//!
3//! This uses the virtual COM port provided on the LP-MSPM0G3507 board. 3//! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0G3507 board.
4 4
5#![no_std] 5#![no_std]
6#![no_main] 6#![no_main]
@@ -10,6 +10,7 @@ use embassy_executor::Spawner;
10use embassy_mspm0::bind_interrupts; 10use embassy_mspm0::bind_interrupts;
11use embassy_mspm0::i2c::{Config, I2c, InterruptHandler}; 11use embassy_mspm0::i2c::{Config, I2c, InterruptHandler};
12use embassy_mspm0::peripherals::I2C1; 12use embassy_mspm0::peripherals::I2C1;
13use embassy_time::Timer;
13use {defmt_rtt as _, panic_halt as _}; 14use {defmt_rtt as _, panic_halt as _};
14 15
15const ADDRESS: u8 = 0x6a; 16const ADDRESS: u8 = 0x6a;
@@ -28,13 +29,22 @@ async fn main(_spawner: Spawner) -> ! {
28 29
29 let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, Config::default())); 30 let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, Config::default()));
30 31
31 let mut to_read = [1u8; 17]; 32 let mut pot_value: u8 = 0;
32 let to_write = [0u8; 17];
33 33
34 match i2c.async_write_read(ADDRESS, &to_write, &mut to_read).await { 34 loop {
35 Ok(()) => info!("Register {}: {}", to_write, to_read[0]), 35 let to_write = [0u8, pot_value];
36 Err(e) => error!("I2c Error: {:?}", e), 36
37 } 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 }
38 41
39 loop {} 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 }
40} 50}