29 lines
777 B
Rust
29 lines
777 B
Rust
// src/i2c/com.rs
|
|
|
|
use embassy_time::{Duration, Timer};
|
|
use esp_hal::{
|
|
i2c::master::{Config, I2c},
|
|
peripherals::Peripherals,
|
|
};
|
|
use log::info;
|
|
|
|
#[embassy_executor::task]
|
|
pub async fn i2c_check() {
|
|
let peripherals = unsafe { Peripherals::steal() };
|
|
let mut i2c = I2c::new(peripherals.I2C0, Config::default())
|
|
.expect("Failed to initialize I2C")
|
|
.with_sda(peripherals.GPIO21)
|
|
.with_scl(peripherals.GPIO22);
|
|
|
|
loop {
|
|
info!("hehe");
|
|
esp_println::println!("I2C bus scan start");
|
|
for addr in 0x03..0x78 {
|
|
if i2c.write(addr, &[]).is_ok() {
|
|
esp_println::println!("Device found at address 0x{:02X}", addr);
|
|
}
|
|
}
|
|
Timer::after(Duration::from_secs(5)).await;
|
|
}
|
|
}
|