aboutsummaryrefslogtreecommitdiff
path: root/examples/mspm0l1306/src/bin/i2c.rs
blob: 51327dff51e47b27eba1d0e7d2df85fb208149e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! This example uses FIFO with polling, and the maximum FIFO size is 8.
//! Refer to async example to handle larger packets.
//!
//! 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::{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 i2c = unwrap!(I2c::new_blocking(instance, scl, sda, Config::default()));

    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 {}
}