2semester hodina 2

This commit is contained in:
Filipriec
2026-03-03 15:47:50 +01:00
parent fae99273c2
commit cfc31e428e
11 changed files with 1690 additions and 0 deletions

60
2sem_i2c/src/bin/main.rs Normal file
View File

@@ -0,0 +1,60 @@
// src/bin/main.rs
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::i2c::I2c;
use embassy_stm32::i2c::Config;
use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
info!("tititititi");
let p = embassy_stm32::init(Default::default());
let mut i2c_cfg = Config::default();
i2c_cfg.sda_pullup = true;
i2c_cfg.scl_pullup = true;
i2c_cfg.timeout = Duration::from_millis(10);
let mut i2c = I2c::new_blocking(p.I2C3, p.PC0, p.PC1, i2c_cfg);
let mg = 0x23;
// for x in 0x00..0x99 {
// let mut data = [0u8; 1];
// match i2c.blocking_read(x, &mut data) {
// Ok(_) => {
// defmt::info!("Found device: 0x{:02x}", x);
// }
// Err(_) => {
// }
// }
// }
let device_addr = 0x23;
let revid_reg = [0x36]; // This is the "Who Am I" register
let mut buffer = [0u8; 1];
match i2c.blocking_write_read(device_addr, &revid_reg, &mut buffer) {
Ok(_) => {
if buffer[0] == 0x22 {
info!("RM3100 detected! ID: 0x{:02x}", buffer[0]);
} else {
warn!("Connected to something, but it's not an RM3100. Got: 0x{:02x}", buffer[0]);
}
}
Err(e) => error!("Could not communicate with RM3100: {}", e),
}
loop {
Timer::after(Duration::from_secs(1)).await;
// let mut data = [0u8; 1];
// if let Ok(_) = i2c.blocking_read(mg, &mut data) {
// defmt::info!("0x{:02x}: {}", mg, data);
// } else {
// defmt::warn!("Device 0x{:02x} not responding", mg);
// }
}
}