I2C detection works well
This commit is contained in:
37
mqtt_display/src/i2c/com.rs
Normal file
37
mqtt_display/src/i2c/com.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
// src/i2c/com.rs
|
||||
|
||||
use embassy_executor::task;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use esp_hal::{
|
||||
gpio::Io,
|
||||
i2c::master::{Config, I2c},
|
||||
peripherals::Peripherals,
|
||||
};
|
||||
use esp_println::println;
|
||||
|
||||
#[task]
|
||||
pub async fn i2c_check() {
|
||||
let peripherals = unsafe { Peripherals::steal() };
|
||||
let _io = Io::new(peripherals.IO_MUX);
|
||||
|
||||
let sda = peripherals.GPIO21;
|
||||
let scl = peripherals.GPIO22;
|
||||
|
||||
let mut i2c = I2c::new(peripherals.I2C0, Config::default())
|
||||
.expect("Failed to initialize I2C")
|
||||
.with_sda(sda)
|
||||
.with_scl(scl);
|
||||
|
||||
loop {
|
||||
println!("I2C bus scan start");
|
||||
// Skenujeme adresy 0x03 až 0x77
|
||||
for addr in 0x03..0x78 {
|
||||
// Skúsime zapísať prázdne dáta na adresu
|
||||
if i2c.write(addr, &[]).is_ok() {
|
||||
println!("Device found at address 0x{:02X}", addr);
|
||||
}
|
||||
}
|
||||
println!("Scan finished");
|
||||
Timer::after(Duration::from_secs(5)).await;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user