diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /examples/mcxa/src/bin/i2c-scan-blocking.rs | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'examples/mcxa/src/bin/i2c-scan-blocking.rs')
| -rw-r--r-- | examples/mcxa/src/bin/i2c-scan-blocking.rs | 40 |
1 files changed, 40 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..bd706d712 --- /dev/null +++ b/examples/mcxa/src/bin/i2c-scan-blocking.rs | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_mcxa::gpio::{Input, Pull}; | ||
| 6 | use embassy_time::Timer; | ||
| 7 | use hal::clocks::config::Div8; | ||
| 8 | use hal::config::Config; | ||
| 9 | use hal::i2c::controller::{self, I2c, Speed}; | ||
| 10 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | ||
| 11 | |||
| 12 | #[embassy_executor::main] | ||
| 13 | async fn main(_spawner: Spawner) { | ||
| 14 | let mut config = Config::default(); | ||
| 15 | config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1); | ||
| 16 | |||
| 17 | let p = hal::init(config); | ||
| 18 | |||
| 19 | defmt::info!("I2C example"); | ||
| 20 | |||
| 21 | let mut config = controller::Config::default(); | ||
| 22 | config.speed = Speed::Standard; | ||
| 23 | |||
| 24 | // Note: P0_2 is connected to P1_8 on the FRDM_MCXA276 via a resistor, and | ||
| 25 | // defaults to SWO on the debug peripheral. Explicitly make it a high-z | ||
| 26 | // input. | ||
| 27 | let _pin = Input::new(p.P0_2, Pull::Disabled); | ||
| 28 | let mut i2c = I2c::new_blocking(p.LPI2C2, p.P1_9, p.P1_8, config).unwrap(); | ||
| 29 | |||
| 30 | for addr in 0x01..=0x7f { | ||
| 31 | let result = i2c.blocking_write(addr, &[]); | ||
| 32 | if result.is_ok() { | ||
| 33 | defmt::info!("Device found at addr {:02x}", addr); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | loop { | ||
| 38 | Timer::after_secs(10).await; | ||
| 39 | } | ||
| 40 | } | ||
