diff options
| author | James Munns <[email protected]> | 2025-12-05 14:28:47 +0100 |
|---|---|---|
| committer | James Munns <[email protected]> | 2025-12-05 14:28:47 +0100 |
| commit | b252db845e19603faf528cf93fe0c44757a27430 (patch) | |
| tree | 99e646d17bed747df244dd607a15f5a67baa530a /examples/mcxa/src/bin/i2c-scan-blocking.rs | |
| parent | 6a1eed83b9df8ffa81b93860f530f5bb3252d996 (diff) | |
Move
Diffstat (limited to 'examples/mcxa/src/bin/i2c-scan-blocking.rs')
| -rw-r--r-- | examples/mcxa/src/bin/i2c-scan-blocking.rs | 41 |
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 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_mcxa::gpio::Pull; | ||
| 6 | use embassy_mcxa::Input; | ||
| 7 | use embassy_time::Timer; | ||
| 8 | use hal::clocks::config::Div8; | ||
| 9 | use hal::config::Config; | ||
| 10 | use hal::i2c::controller::{self, I2c, Speed}; | ||
| 11 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async 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 | } | ||
