aboutsummaryrefslogtreecommitdiff
path: root/examples/mspm0l1306/src/bin/i2c.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/mspm0l1306/src/bin/i2c.rs')
-rw-r--r--examples/mspm0l1306/src/bin/i2c.rs28
1 files changed, 19 insertions, 9 deletions
diff --git a/examples/mspm0l1306/src/bin/i2c.rs b/examples/mspm0l1306/src/bin/i2c.rs
index 51327dff5..e8801c485 100644
--- a/examples/mspm0l1306/src/bin/i2c.rs
+++ b/examples/mspm0l1306/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-MSPM0L1306 board. 4//! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0L1306 board.
5 5
6#![no_std] 6#![no_std]
7#![no_main] 7#![no_main]
@@ -9,9 +9,10 @@
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 = 0x2c;
15 16
16#[embassy_executor::main] 17#[embassy_executor::main]
17async fn main(_spawner: Spawner) -> ! { 18async fn main(_spawner: Spawner) -> ! {
@@ -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}