needs redesign
This commit is contained in:
@@ -22,39 +22,15 @@ async fn main(_spawner: Spawner) {
|
|||||||
let mut i2c = I2c::new_blocking(p.I2C3, p.PC0, p.PC1, i2c_cfg);
|
let mut i2c = I2c::new_blocking(p.I2C3, p.PC0, p.PC1, i2c_cfg);
|
||||||
|
|
||||||
let mg = 0x23;
|
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 {
|
loop {
|
||||||
Timer::after(Duration::from_secs(1)).await;
|
Timer::after(Duration::from_secs(1)).await;
|
||||||
|
|
||||||
// let mut data = [0u8; 1];
|
let mut data = [0u8; 1];
|
||||||
// if let Ok(_) = i2c.blocking_read(mg, &mut data) {
|
if let Ok(_) = i2c.blocking_read(mg, &mut data) {
|
||||||
// defmt::info!("0x{:02x}: {}", mg, data);
|
defmt::info!("0x{:02x}: {}", mg, data);
|
||||||
// } else {
|
} else {
|
||||||
// defmt::warn!("Device 0x{:02x} not responding", mg);
|
defmt::warn!("Device 0x{:02x} not responding", mg);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user