I2C detection works well

This commit is contained in:
Priec
2026-01-08 20:55:28 +01:00
parent 70c37c344b
commit d8b4352a0f
16 changed files with 2388 additions and 0 deletions

View 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;
}
}