From d4ffff2c6e686b07a205689706bfaada4a24a490 Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Mon, 11 Nov 2019 17:35:22 +0100 Subject: [PATCH 01/12] Initial SHT4x support --- .gitignore | 2 + Makefile | 2 +- sht4x/Makefile | 14 ++++ sht4x/default_config.inc | 28 ++++++++ sht4x/sht4x.c | 120 +++++++++++++++++++++++++++++++ sht4x/sht4x.h | 139 ++++++++++++++++++++++++++++++++++++ sht4x/sht4x_example_usage.c | 71 ++++++++++++++++++ sht4x/user_config.inc | 26 +++++++ 8 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 sht4x/Makefile create mode 100644 sht4x/default_config.inc create mode 100644 sht4x/sht4x.c create mode 100644 sht4x/sht4x.h create mode 100644 sht4x/sht4x_example_usage.c create mode 100644 sht4x/user_config.inc diff --git a/.gitignore b/.gitignore index 425b9e2..0a15263 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ /release /sht3x/sht3x_example_usage /sht3x/user_config.inc +/sht4x/sht4x_example_usage +/sht4x/user_config.inc /shtc1/shtc1_example_usage /shtc1/user_config.inc /sht-common/sht_git_version.c diff --git a/Makefile b/Makefile index 033270f..b65b1f2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -drivers=sht3x shtc1 +drivers=sht3x sht4x shtc1 sample-projects=shtc3-stm32-uvision clean_drivers=$(foreach d, $(drivers), clean_$(d)) release_drivers=$(foreach d, $(drivers), release/$(d)) diff --git a/sht4x/Makefile b/sht4x/Makefile new file mode 100644 index 0000000..cac7729 --- /dev/null +++ b/sht4x/Makefile @@ -0,0 +1,14 @@ +# See user_config.inc for build customization +-include user_config.inc +include default_config.inc + + +.PHONY: all clean + +all: sht4x_example_usage + +sht4x_example_usage: clean + $(CC) $(CFLAGS) -o $@ ${sht4x_sources} ${${CONFIG_I2C_TYPE}_sources} ${sht4x_dir}/sht4x_example_usage.c + +clean: + $(RM) sht4x_example_usage diff --git a/sht4x/default_config.inc b/sht4x/default_config.inc new file mode 100644 index 0000000..bfbe8c7 --- /dev/null +++ b/sht4x/default_config.inc @@ -0,0 +1,28 @@ +sht_driver_dir ?= .. +sensirion_common_dir ?= ${sht_driver_dir}/embedded-common +sht_common_dir ?= ${sht_driver_dir}/sht-common +sht4x_dir ?= ${sht_driver_dir}/sht4x +CONFIG_I2C_TYPE ?= hw_i2c + +sw_i2c_impl_src ?= ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c +hw_i2c_impl_src ?= ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c + +CFLAGS ?= -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC +CFLAGS += -I${sensirion_common_dir} -I${sht_common_dir} -I${sht4x_dir} \ + -I${sensirion_common_dir}/${CONFIG_I2C_TYPE} + +sensirion_common_sources = ${sensirion_common_dir}/sensirion_arch_config.h \ + ${sensirion_common_dir}/sensirion_i2c.h \ + ${sensirion_common_dir}/sensirion_common.h \ + ${sensirion_common_dir}/sensirion_common.c + +sht_common_sources = ${sht_common_dir}/sht_git_version.h \ + ${sht_common_dir}/sht_git_version.c + +sht4x_sources = ${sensirion_common_sources} ${sht_common_sources} \ + ${sht4x_dir}/sht4x.h ${sht4x_dir}/sht4x.c + +hw_i2c_sources = ${hw_i2c_impl_src} +sw_i2c_sources = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_gpio.h \ + ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c.c \ + ${sw_i2c_impl_src} diff --git a/sht4x/sht4x.c b/sht4x/sht4x.c new file mode 100644 index 0000000..1e43972 --- /dev/null +++ b/sht4x/sht4x.c @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2019, Sensirion AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Sensirion AG nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * + * \brief Sensirion SHT4X driver implementation + * + * This module provides access to the SHT4X functionality over a generic I2C + * interface. It supports measurements without clock stretching only. + */ + +#include "sht4x.h" +#include "sensirion_arch_config.h" +#include "sensirion_common.h" +#include "sensirion_i2c.h" + +/* all measurement commands return T (CRC) RH (CRC) */ +#define SHT4X_CMD_MEASURE_HPM 0xFD +#define SHT4X_CMD_MEASURE_LPM 0xEB +#define SHT4X_CMD_READ_SERIAL 0x89 +#define SHT4X_CMD_DURATION_USEC 1000 + +#define SHT4X_ADDRESS 0x44 + +static uint8_t sht4x_cmd_measure = SHT4X_CMD_MEASURE_HPM; + +int16_t sht4x_measure_blocking_read(int32_t *temperature, int32_t *humidity) { + int16_t ret; + + ret = sht4x_measure(); + if (ret) + return ret; + sensirion_sleep_usec(SHT4X_MEASUREMENT_DURATION_USEC); + return sht4x_read(temperature, humidity); +} + +int16_t sht4x_measure(void) { + return sensirion_i2c_write(SHT4X_ADDRESS, &sht4x_cmd_measure, 1); +} + +int16_t sht4x_read(int32_t *temperature, int32_t *humidity) { + uint16_t words[2]; + int16_t ret = sensirion_i2c_read_words(SHT4X_ADDRESS, words, + SENSIRION_NUM_WORDS(words)); + /** + * formulas for conversion of the sensor signals, optimized for fixed point + * algebra: + * Temperature = 175 * S_T / 2^16 - 45 + * Relative Humidity = 125 * (S_RH / 2^16) - 6 + */ + *temperature = ((21875 * (int32_t)words[0]) >> 13) - 45000; + *humidity = ((15625 * (int32_t)words[1]) >> 13) - 6000; + + return ret; +} + +int16_t sht4x_probe(void) { + uint32_t serial; + + return sht4x_read_serial(&serial); +} + +void sht4x_enable_low_power_mode(uint8_t enable_low_power_mode) { + sht4x_cmd_measure = + enable_low_power_mode ? SHT4X_CMD_MEASURE_LPM : SHT4X_CMD_MEASURE_HPM; +} + +int16_t sht4x_read_serial(uint32_t *serial) { + const uint8_t cmd = SHT4X_CMD_READ_SERIAL; + int16_t ret; + uint16_t serial_words[SENSIRION_NUM_WORDS(*serial)]; + + ret = sensirion_i2c_write(SHT4X_ADDRESS, &cmd, 1); + if (ret) + return ret; + + sensirion_sleep_usec(SHT4X_MEASUREMENT_DURATION_USEC); + ret = sensirion_i2c_read_words(SHT4X_ADDRESS, serial_words, + SENSIRION_NUM_WORDS(serial_words)); + *serial = ((uint32_t)serial_words[0] << 16) | serial_words[1]; + + return ret; +} + +const char *sht4x_get_driver_version(void) { + return SHT_DRV_VERSION_STR; +} + +uint8_t sht4x_get_configured_address(void) { + return SHT4X_ADDRESS; +} diff --git a/sht4x/sht4x.h b/sht4x/sht4x.h new file mode 100644 index 0000000..ccadfba --- /dev/null +++ b/sht4x/sht4x.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2018, Sensirion AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Sensirion AG nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * \file + * + * \brief Sensirion SHT driver interface + * + * This module provides access to the SHT functionality over a generic I2C + * interface. It supports measurements without clock stretching only. + */ + +#ifndef SHT4X_H +#define SHT4X_H + +#include "sensirion_arch_config.h" +#include "sensirion_i2c.h" +#include "sht_git_version.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATUS_OK 0 +#define STATUS_ERR_BAD_DATA (-1) +#define STATUS_CRC_FAIL (-2) +#define STATUS_UNKNOWN_DEVICE (-3) +#define SHT4X_MEASUREMENT_DURATION_USEC 25000 + +/** + * Detects if a sensor is connected by reading out the ID register. + * If the sensor does not answer or if the answer is not the expected value, + * the test fails. + * + * @return 0 if a sensor was detected + */ +int16_t sht4x_probe(void); + +/** + * Starts a measurement and then reads out the results. This function blocks + * while the measurement is in progress. The duration of the measurement depends + * on the sensor in use, please consult the datasheet. + * Temperature is returned in [degree Celsius], multiplied by 1000, + * and relative humidity in [percent relative humidity], multiplied by 1000. + * + * @param temperature the address for the result of the temperature + * measurement + * @param humidity the address for the result of the relative humidity + * measurement + * @return 0 if the command was successful, else an error code. + */ +int16_t sht4x_measure_blocking_read(int32_t *temperature, int32_t *humidity); + +/** + * Starts a measurement in high precision mode. Use sht4x_read() to read out the + * values, once the measurement is done. The duration of the measurement depends + * on the sensor in use, please consult the datasheet. + * + * @return 0 if the command was successful, else an error code. + */ +int16_t sht4x_measure(void); + +/** + * Reads out the results of a measurement that was previously started by + * sht4x_measure(). If the measurement is still in progress, this function + * returns an error. + * Temperature is returned in [degree Celsius], multiplied by 1000, + * and relative humidity in [percent relative humidity], multiplied by 1000. + * + * @param temperature the address for the result of the temperature + * measurement + * @param humidity the address for the result of the relative humidity + * measurement + * @return 0 if the command was successful, else an error code. + */ +int16_t sht4x_read(int32_t *temperature, int32_t *humidity); + +/** + * Enable or disable the SHT's low power mode + * + * @param enable_low_power_mode 1 to enable low power mode, 0 to disable + */ +void sht4x_enable_low_power_mode(uint8_t enable_low_power_mode); + +/** + * Read out the serial number + * + * @param serial the address for the result of the serial number + * @return 0 if the command was successful, else an error code. + */ +int16_t sht4x_read_serial(uint32_t *serial); + +/** + * Return the driver version + * + * @return Driver version string + */ +const char *sht4x_get_driver_version(void); + +/** + * Returns the configured SHT3x address. + * + * @return SHT3x_ADDRESS + */ +uint8_t sht4x_get_configured_address(void); + +#ifdef __cplusplus +} +#endif + +#endif /* SHT4X_H */ diff --git a/sht4x/sht4x_example_usage.c b/sht4x/sht4x_example_usage.c new file mode 100644 index 0000000..fa02be1 --- /dev/null +++ b/sht4x/sht4x_example_usage.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2019, Sensirion AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Sensirion AG nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include // printf +#include "sht4x.h" + +/** + * TO USE CONSOLE OUTPUT (PRINTF) AND WAIT (SLEEP) PLEASE ADAPT THEM TO YOUR + * PLATFORM + */ + +int main(void) { + /* Initialize the i2c bus for the current platform */ + sensirion_i2c_init(); + + /* Busy loop for initialization, because the main loop does not work without + * a sensor. + */ + while (sht4x_probe() != STATUS_OK) { + printf("SHT sensor probing failed\n"); + sensirion_sleep_usec(1000000); /* sleep 1s */ + } + printf("SHT sensor probing successful\n"); + + while (1) { + int32_t temperature, humidity; + /* Measure temperature and relative humidity and store into variables + * temperature, humidity (each output multiplied by 1000). + */ + int8_t ret = sht4x_measure_blocking_read(&temperature, &humidity); + if (ret == STATUS_OK) { + printf("measured temperature: %0.2f degreeCelsius, " + "measured humidity: %0.2f percentRH\n", + temperature / 1000.0f, + humidity / 1000.0f); + } else { + printf("error reading measurement\n"); + } + + sensirion_sleep_usec(1000000); /* sleep 1s */ + } + return 0; +} diff --git a/sht4x/user_config.inc b/sht4x/user_config.inc new file mode 100644 index 0000000..4a05588 --- /dev/null +++ b/sht4x/user_config.inc @@ -0,0 +1,26 @@ +## This file controls the custom user build settings. + +## Choose either of hw_i2c or sw_i2c depending on whether you have a dedicated +## i2c controller (hw_i2c) or are using bit-banging on GPIOs (sw_i2c) +# CONFIG_I2C_TYPE = hw_i2c + +## For hw_i2c, configure the i2c HAL implementation to use. +## Use one of the available sample-implementations or implement your own using +## the stub. +# hw_i2c_impl_src = ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c + +## For sw_i2c, configure the GPIO implementation. +# sw_i2c_impl_src = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c + +## +## The items below are listed as documentation but may not need customization +## + +## The build paths can also be changed here if needed +# sht_driver_dir = .. +# sensirion_common_dir = ${sht_driver_dir}/embedded-common +# sht_common_dir = ${sht_driver_dir}/sht-common +# sht4x_dir = ${sht_driver_dir}/sht4x + +## If you need different CFLAGS, those can be customized as well +# CFLAGS = -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC From 08b9243d22b7771a8bb034cf66cece1c1c19e4c7 Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Tue, 12 Nov 2019 11:15:18 +0100 Subject: [PATCH 02/12] Trigger SHT4x pipeline --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d3cce20..f04a684 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ trigger_testbed: - > curl --request POST - --form ref=master + --form ref=sht4x --form token=$CI_JOB_TOKEN --form "variables[DRIVER_NAMES]=embedded-sht" --form "variables[DRIVER_BRANCH]=$CI_COMMIT_REF_NAME" From 439134d3032686540f34dc06e8ba2c94872e979e Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Thu, 11 Jun 2020 08:56:23 +0200 Subject: [PATCH 03/12] SHT4x: Use measurement delay according to measurement mode --- sht4x/sht4x.c | 12 +++++++++--- sht4x/sht4x.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sht4x/sht4x.c b/sht4x/sht4x.c index 1e43972..04335df 100644 --- a/sht4x/sht4x.c +++ b/sht4x/sht4x.c @@ -52,6 +52,7 @@ #define SHT4X_ADDRESS 0x44 static uint8_t sht4x_cmd_measure = SHT4X_CMD_MEASURE_HPM; +static uint16_t sht4x_cmd_measure_delay_us = SHT4X_MEASUREMENT_DURATION_USEC; int16_t sht4x_measure_blocking_read(int32_t *temperature, int32_t *humidity) { int16_t ret; @@ -59,7 +60,7 @@ int16_t sht4x_measure_blocking_read(int32_t *temperature, int32_t *humidity) { ret = sht4x_measure(); if (ret) return ret; - sensirion_sleep_usec(SHT4X_MEASUREMENT_DURATION_USEC); + sensirion_sleep_usec(sht4x_cmd_measure_delay_us); return sht4x_read(temperature, humidity); } @@ -90,8 +91,13 @@ int16_t sht4x_probe(void) { } void sht4x_enable_low_power_mode(uint8_t enable_low_power_mode) { - sht4x_cmd_measure = - enable_low_power_mode ? SHT4X_CMD_MEASURE_LPM : SHT4X_CMD_MEASURE_HPM; + if (enable_low_power_mode) { + sht4x_cmd_measure = SHT4X_CMD_MEASURE_LPM; + sht4x_cmd_measure_delay_us = SHT4X_MEASUREMENT_DURATION_LPM_USEC; + } else { + sht4x_cmd_measure = SHT4X_CMD_MEASURE_HPM; + sht4x_cmd_measure_delay_us = SHT4X_MEASUREMENT_DURATION_USEC; + } } int16_t sht4x_read_serial(uint32_t *serial) { diff --git a/sht4x/sht4x.h b/sht4x/sht4x.h index ccadfba..62332df 100644 --- a/sht4x/sht4x.h +++ b/sht4x/sht4x.h @@ -53,7 +53,8 @@ extern "C" { #define STATUS_ERR_BAD_DATA (-1) #define STATUS_CRC_FAIL (-2) #define STATUS_UNKNOWN_DEVICE (-3) -#define SHT4X_MEASUREMENT_DURATION_USEC 25000 +#define SHT4X_MEASUREMENT_DURATION_USEC 10000 /* 10ms "high repeatability" */ +#define SHT4X_MEASUREMENT_DURATION_LPM_USEC 2500 /* 2.5ms "low repeatability" */ /** * Detects if a sensor is connected by reading out the ID register. From d92c11f125484d0052388b18ed06b7fa0a04c802 Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Thu, 11 Jun 2020 08:57:41 +0200 Subject: [PATCH 04/12] SHT4x: Use 2^16-1 in conversion formula --- sht4x/sht4x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sht4x/sht4x.c b/sht4x/sht4x.c index 04335df..4c53c8e 100644 --- a/sht4x/sht4x.c +++ b/sht4x/sht4x.c @@ -75,8 +75,8 @@ int16_t sht4x_read(int32_t *temperature, int32_t *humidity) { /** * formulas for conversion of the sensor signals, optimized for fixed point * algebra: - * Temperature = 175 * S_T / 2^16 - 45 - * Relative Humidity = 125 * (S_RH / 2^16) - 6 + * Temperature = 175 * S_T / 65535 - 45 + * Relative Humidity = 125 * (S_RH / 65535) - 6 */ *temperature = ((21875 * (int32_t)words[0]) >> 13) - 45000; *humidity = ((15625 * (int32_t)words[1]) >> 13) - 6000; From f61242f9d984262371684f3b7c3deeac6fadd01f Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Thu, 11 Jun 2020 09:06:14 +0200 Subject: [PATCH 05/12] SHT4x: Shorten delay when reading out serial The wrong timing was used. For the read_serial command we only need to wait a short amount of time, not the time a measurement takes. --- sht4x/sht4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sht4x/sht4x.c b/sht4x/sht4x.c index 4c53c8e..4b30fa5 100644 --- a/sht4x/sht4x.c +++ b/sht4x/sht4x.c @@ -109,7 +109,7 @@ int16_t sht4x_read_serial(uint32_t *serial) { if (ret) return ret; - sensirion_sleep_usec(SHT4X_MEASUREMENT_DURATION_USEC); + sensirion_sleep_usec(SHT4X_CMD_DURATION_USEC); ret = sensirion_i2c_read_words(SHT4X_ADDRESS, serial_words, SENSIRION_NUM_WORDS(serial_words)); *serial = ((uint32_t)serial_words[0] << 16) | serial_words[1]; From 81ea43ef21f9d60f0c340a545b0e8c36d8864d2f Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Thu, 11 Jun 2020 09:06:43 +0200 Subject: [PATCH 06/12] SHT4x: Use low-power measurement command from datasheet Use the ultra-low-power measurement mode provided in the datasheet. Slightly more noisy than the previous low-power mode. --- sht4x/sht4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sht4x/sht4x.c b/sht4x/sht4x.c index 4b30fa5..3881bd6 100644 --- a/sht4x/sht4x.c +++ b/sht4x/sht4x.c @@ -45,7 +45,7 @@ /* all measurement commands return T (CRC) RH (CRC) */ #define SHT4X_CMD_MEASURE_HPM 0xFD -#define SHT4X_CMD_MEASURE_LPM 0xEB +#define SHT4X_CMD_MEASURE_LPM 0xE0 #define SHT4X_CMD_READ_SERIAL 0x89 #define SHT4X_CMD_DURATION_USEC 1000 From fdfd416e046d474bb2eec1270f656370ea0730d7 Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Wed, 9 Sep 2020 13:33:33 +0200 Subject: [PATCH 07/12] Revert "Trigger SHT4x pipeline" This reverts commit 08b9243d22b7771a8bb034cf66cece1c1c19e4c7. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f04a684..d3cce20 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ trigger_testbed: - > curl --request POST - --form ref=sht4x + --form ref=master --form token=$CI_JOB_TOKEN --form "variables[DRIVER_NAMES]=embedded-sht" --form "variables[DRIVER_BRANCH]=$CI_COMMIT_REF_NAME" From 2647416ef3e730bf7013c2b5200b0bcdffc9b2b9 Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Wed, 9 Sep 2020 13:30:21 +0200 Subject: [PATCH 08/12] SHT4x: fix code style Run make style-fix --- sht4x/sht4x.c | 8 ++++---- sht4x/sht4x.h | 12 +++++++----- sht4x/sht4x_example_usage.c | 5 ++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/sht4x/sht4x.c b/sht4x/sht4x.c index 3881bd6..7aafec9 100644 --- a/sht4x/sht4x.c +++ b/sht4x/sht4x.c @@ -54,7 +54,7 @@ static uint8_t sht4x_cmd_measure = SHT4X_CMD_MEASURE_HPM; static uint16_t sht4x_cmd_measure_delay_us = SHT4X_MEASUREMENT_DURATION_USEC; -int16_t sht4x_measure_blocking_read(int32_t *temperature, int32_t *humidity) { +int16_t sht4x_measure_blocking_read(int32_t* temperature, int32_t* humidity) { int16_t ret; ret = sht4x_measure(); @@ -68,7 +68,7 @@ int16_t sht4x_measure(void) { return sensirion_i2c_write(SHT4X_ADDRESS, &sht4x_cmd_measure, 1); } -int16_t sht4x_read(int32_t *temperature, int32_t *humidity) { +int16_t sht4x_read(int32_t* temperature, int32_t* humidity) { uint16_t words[2]; int16_t ret = sensirion_i2c_read_words(SHT4X_ADDRESS, words, SENSIRION_NUM_WORDS(words)); @@ -100,7 +100,7 @@ void sht4x_enable_low_power_mode(uint8_t enable_low_power_mode) { } } -int16_t sht4x_read_serial(uint32_t *serial) { +int16_t sht4x_read_serial(uint32_t* serial) { const uint8_t cmd = SHT4X_CMD_READ_SERIAL; int16_t ret; uint16_t serial_words[SENSIRION_NUM_WORDS(*serial)]; @@ -117,7 +117,7 @@ int16_t sht4x_read_serial(uint32_t *serial) { return ret; } -const char *sht4x_get_driver_version(void) { +const char* sht4x_get_driver_version(void) { return SHT_DRV_VERSION_STR; } diff --git a/sht4x/sht4x.h b/sht4x/sht4x.h index 62332df..61205f9 100644 --- a/sht4x/sht4x.h +++ b/sht4x/sht4x.h @@ -54,7 +54,9 @@ extern "C" { #define STATUS_CRC_FAIL (-2) #define STATUS_UNKNOWN_DEVICE (-3) #define SHT4X_MEASUREMENT_DURATION_USEC 10000 /* 10ms "high repeatability" */ -#define SHT4X_MEASUREMENT_DURATION_LPM_USEC 2500 /* 2.5ms "low repeatability" */ +#define SHT4X_MEASUREMENT_DURATION_LPM_USEC \ + 2500 /* 2.5ms "low repeatability" \ + */ /** * Detects if a sensor is connected by reading out the ID register. @@ -78,7 +80,7 @@ int16_t sht4x_probe(void); * measurement * @return 0 if the command was successful, else an error code. */ -int16_t sht4x_measure_blocking_read(int32_t *temperature, int32_t *humidity); +int16_t sht4x_measure_blocking_read(int32_t* temperature, int32_t* humidity); /** * Starts a measurement in high precision mode. Use sht4x_read() to read out the @@ -102,7 +104,7 @@ int16_t sht4x_measure(void); * measurement * @return 0 if the command was successful, else an error code. */ -int16_t sht4x_read(int32_t *temperature, int32_t *humidity); +int16_t sht4x_read(int32_t* temperature, int32_t* humidity); /** * Enable or disable the SHT's low power mode @@ -117,14 +119,14 @@ void sht4x_enable_low_power_mode(uint8_t enable_low_power_mode); * @param serial the address for the result of the serial number * @return 0 if the command was successful, else an error code. */ -int16_t sht4x_read_serial(uint32_t *serial); +int16_t sht4x_read_serial(uint32_t* serial); /** * Return the driver version * * @return Driver version string */ -const char *sht4x_get_driver_version(void); +const char* sht4x_get_driver_version(void); /** * Returns the configured SHT3x address. diff --git a/sht4x/sht4x_example_usage.c b/sht4x/sht4x_example_usage.c index fa02be1..a2d6d38 100644 --- a/sht4x/sht4x_example_usage.c +++ b/sht4x/sht4x_example_usage.c @@ -29,8 +29,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include // printf #include "sht4x.h" +#include // printf /** * TO USE CONSOLE OUTPUT (PRINTF) AND WAIT (SLEEP) PLEASE ADAPT THEM TO YOUR @@ -59,8 +59,7 @@ int main(void) { if (ret == STATUS_OK) { printf("measured temperature: %0.2f degreeCelsius, " "measured humidity: %0.2f percentRH\n", - temperature / 1000.0f, - humidity / 1000.0f); + temperature / 1000.0f, humidity / 1000.0f); } else { printf("error reading measurement\n"); } From e9aa8502860b994ef9cb36ca6034c8a37fdfaae6 Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Wed, 9 Sep 2020 13:36:03 +0200 Subject: [PATCH 09/12] SHT4x: Update copyright year to 2020 2020 is the year of initial release --- sht4x/sht4x.c | 2 +- sht4x/sht4x.h | 2 +- sht4x/sht4x_example_usage.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sht4x/sht4x.c b/sht4x/sht4x.c index 7aafec9..18b6567 100644 --- a/sht4x/sht4x.c +++ b/sht4x/sht4x.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Sensirion AG + * Copyright (c) 2020, Sensirion AG * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sht4x/sht4x.h b/sht4x/sht4x.h index 61205f9..a216360 100644 --- a/sht4x/sht4x.h +++ b/sht4x/sht4x.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Sensirion AG + * Copyright (c) 2020, Sensirion AG * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sht4x/sht4x_example_usage.c b/sht4x/sht4x_example_usage.c index a2d6d38..6511bf1 100644 --- a/sht4x/sht4x_example_usage.c +++ b/sht4x/sht4x_example_usage.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Sensirion AG + * Copyright (c) 2020, Sensirion AG * All rights reserved. * * Redistribution and use in source and binary forms, with or without From 7d256fe67b1d8f96a6ec8acd3466f512078a22ef Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Wed, 9 Sep 2020 13:39:57 +0200 Subject: [PATCH 10/12] Update README to include SHT4x and utils directories * Add SHT4x driver to the readme * Add utils directory to the readme --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae548ad..e9467db 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,11 @@ cloning the repository. ## Repository content * `embedded-common` submodule repository for the common embedded driver HAL * `sht-common` common files for all SHTxx drivers, humidity conversion functions -* `sht3x` SHT3x/SHT8x driver related -* `shtc1` SHTC3/SHTC1/SHTW1/SHTW2 driver related +* `sht4x` SHT4 driver +* `sht3x` SHT3x/SHT8x driver +* `shtc1` SHTC3/SHTC1/SHTW1/SHTW2 driver +* `utils` Conversion functions (Centigrade to Fahrenheit, %RH relative humidity + to aboslute humidity) ## Collecting resources ``` From f8c91d374f8146af5f2950ceaeb6332c861c94ac Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Wed, 9 Sep 2020 13:43:26 +0200 Subject: [PATCH 11/12] Update Changelog to include SHT4x Support --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 666acda..09ae460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] + * [`added`] SHT4x Support + ## [5.1.0] - 2020-06-12 * [`changed`] Cleanup and better document stm32 sample code From 4cb88554a39fb1e639ca727ff80ca525f27e1341 Mon Sep 17 00:00:00 2001 From: Andreas Brauchli Date: Wed, 9 Sep 2020 17:04:06 +0200 Subject: [PATCH 12/12] SHT4x: Fix typo * Fix copy-paste typo in docstr SHT3x -> SHT4x --- sht4x/sht4x.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sht4x/sht4x.h b/sht4x/sht4x.h index a216360..03ee4a6 100644 --- a/sht4x/sht4x.h +++ b/sht4x/sht4x.h @@ -129,9 +129,9 @@ int16_t sht4x_read_serial(uint32_t* serial); const char* sht4x_get_driver_version(void); /** - * Returns the configured SHT3x address. + * Returns the configured SHT4x address. * - * @return SHT3x_ADDRESS + * @return SHT4x_ADDRESS */ uint8_t sht4x_get_configured_address(void);