From ea00c2bc1a1a3e65ac318993d3bb4cdd7f6767b6 Mon Sep 17 00:00:00 2001 From: Fabio Mendes Date: Sat, 24 Aug 2024 13:19:56 -0400 Subject: [PATCH] Fix mcp9808 temperature conversion --- src/temperature.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/temperature.rs b/src/temperature.rs index 20db679..2c2541f 100644 --- a/src/temperature.rs +++ b/src/temperature.rs @@ -22,8 +22,6 @@ pub async fn init(mut twi: Twim<'static, impl twim::Instance>) -> ! { defmt::error!("Error setting sensor resolution {}", e) } else { set_resolution = false; - // Give some time for the sensor to begin normal operation - Timer::after_millis(400).await; } } let temperature = match read_temperature(&mut twi).await { @@ -49,23 +47,29 @@ async fn read_temperature(twi: &mut Twim<'_, impl twim::Instance>) -> Result i16 { + // clear any bits after bit 11 and shift; + let val = ((upper & 0x1f) as i16) << 8 | lower as i16; + (val << 4) >> 4 }