diff options
Diffstat (limited to 'examples/src/bin')
| -rw-r--r-- | examples/src/bin/i2c-blocking.rs | 31 | ||||
| -rw-r--r-- | examples/src/bin/i2c-scan-blocking.rs | 34 |
2 files changed, 65 insertions, 0 deletions
diff --git a/examples/src/bin/i2c-blocking.rs b/examples/src/bin/i2c-blocking.rs new file mode 100644 index 000000000..0f6c8cbae --- /dev/null +++ b/examples/src/bin/i2c-blocking.rs | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_time::Timer; | ||
| 6 | use hal::clocks::config::Div8; | ||
| 7 | use hal::config::Config; | ||
| 8 | use hal::i2c::controller::{self, I2c, Speed}; | ||
| 9 | use tmp108::Tmp108; | ||
| 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 | let i2c = I2c::new_blocking(p.LPI2C3, p.P3_27, p.P3_28, config).unwrap(); | ||
| 24 | let mut tmp = Tmp108::new_with_a0_gnd(i2c); | ||
| 25 | |||
| 26 | loop { | ||
| 27 | let temperature = tmp.temperature().unwrap(); | ||
| 28 | defmt::info!("Temperature: {}C", temperature); | ||
| 29 | Timer::after_secs(1).await; | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/examples/src/bin/i2c-scan-blocking.rs b/examples/src/bin/i2c-scan-blocking.rs new file mode 100644 index 000000000..6d1247e7a --- /dev/null +++ b/examples/src/bin/i2c-scan-blocking.rs | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_time::Timer; | ||
| 6 | use hal::clocks::config::Div8; | ||
| 7 | use hal::config::Config; | ||
| 8 | use hal::i2c::controller::{self, I2c, Speed}; | ||
| 9 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async fn main(_spawner: Spawner) { | ||
| 13 | let mut config = Config::default(); | ||
| 14 | config.clock_cfg.sirc.fro_lf_div = Div8::from_divisor(1); | ||
| 15 | |||
| 16 | let p = hal::init(config); | ||
| 17 | |||
| 18 | defmt::info!("I2C example"); | ||
| 19 | |||
| 20 | let mut config = controller::Config::default(); | ||
| 21 | config.speed = Speed::Standard; | ||
| 22 | let mut i2c = I2c::new_blocking(p.LPI2C3, p.P3_27, p.P3_28, config).unwrap(); | ||
| 23 | |||
| 24 | for addr in 0x01..=0x7f { | ||
| 25 | let result = i2c.blocking_write(addr, &[]); | ||
| 26 | if result.is_ok() { | ||
| 27 | defmt::info!("Device found at addr {:02x}", addr); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | loop { | ||
| 32 | Timer::after_secs(10).await; | ||
| 33 | } | ||
| 34 | } | ||
