aboutsummaryrefslogtreecommitdiff
path: root/examples/mcxa/src/bin/i2c-scan-blocking.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/mcxa/src/bin/i2c-scan-blocking.rs')
-rw-r--r--examples/mcxa/src/bin/i2c-scan-blocking.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/mcxa/src/bin/i2c-scan-blocking.rs b/examples/mcxa/src/bin/i2c-scan-blocking.rs
new file mode 100644
index 000000000..4e203597b
--- /dev/null
+++ b/examples/mcxa/src/bin/i2c-scan-blocking.rs
@@ -0,0 +1,41 @@
1#![no_std]
2#![no_main]
3
4use embassy_executor::Spawner;
5use embassy_mcxa::gpio::Pull;
6use embassy_mcxa::Input;
7use embassy_time::Timer;
8use hal::clocks::config::Div8;
9use hal::config::Config;
10use hal::i2c::controller::{self, I2c, Speed};
11use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let mut config = Config::default();
16 config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1);
17
18 let p = hal::init(config);
19
20 defmt::info!("I2C example");
21
22 let mut config = controller::Config::default();
23 config.speed = Speed::Standard;
24
25 // Note: P0_2 is connected to P1_8 on the FRDM_MCXA276 via a resistor, and
26 // defaults to SWO on the debug peripheral. Explicitly make it a high-z
27 // input.
28 let _pin = Input::new(p.P0_2, Pull::Disabled);
29 let mut i2c = I2c::new_blocking(p.LPI2C2, p.P1_9, p.P1_8, config).unwrap();
30
31 for addr in 0x01..=0x7f {
32 let result = i2c.blocking_write(addr, &[]);
33 if result.is_ok() {
34 defmt::info!("Device found at addr {:02x}", addr);
35 }
36 }
37
38 loop {
39 Timer::after_secs(10).await;
40 }
41}