From 00811846d5f55367de6a06fd4c87c510c7a8376f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20=C5=BDaitl=C3=ADk?= Date: Sun, 18 Jul 2021 11:42:48 +0200 Subject: [PATCH] Multiplied the temperature by 10 to get better accuracy. NACK is making problems again after I2C transmit. --- fw/Core/Src/scd4x.c | 2 +- fw/Core/Src/sht4x.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fw/Core/Src/scd4x.c b/fw/Core/Src/scd4x.c index b146763..b39fcdf 100644 --- a/fw/Core/Src/scd4x.c +++ b/fw/Core/Src/scd4x.c @@ -88,7 +88,7 @@ int8_t scd4x_read_measurement(int * co2, int *temperature, int *relative_humidit uint32_t co2_ticks = (buffer[0] << 8) + buffer[1]; uint32_t t_ticks = (buffer[3] << 8) + buffer[4]; uint32_t rh_ticks = (buffer[6] << 8) + buffer[7]; - int t_degC = -45 + 175 * t_ticks / 65535; + int t_degC = 10*(-45 + 175 * t_ticks / 65535); int rh_pRH = 100 * rh_ticks / 65535; if (rh_pRH > 100) { rh_pRH = 100; diff --git a/fw/Core/Src/sht4x.c b/fw/Core/Src/sht4x.c index 305083a..f07d94c 100644 --- a/fw/Core/Src/sht4x.c +++ b/fw/Core/Src/sht4x.c @@ -25,9 +25,11 @@ int8_t sht4x_measure(int *temperature, int *relative_humidity) // start measurement buffer[0] = START_MEAS_HIGH_PRECISION; result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1); + // TODO: Proc to vraci NACK? Vyresit. + /* if (result != I2C_OK) { return SHT4X_ERROR; - } + }*/ LL_mDelay(100); // 10 ms should be enough // read out result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6); @@ -38,7 +40,7 @@ int8_t sht4x_measure(int *temperature, int *relative_humidity) // Convert to T and RH; taken directly from pseudocode in SHT4x datasheet, page 3 uint32_t t_ticks = (buffer[0] << 8) + buffer[1]; uint32_t rh_ticks = (buffer[3] << 8) + buffer[4]; - int t_degC = -45 + 175 * t_ticks / 65535; + int t_degC = 10*(-45 + 175 * t_ticks / 65535); int rh_pRH = -6 + 125 * rh_ticks / 65535; if (rh_pRH > 100) { rh_pRH = 100;