├── .gitmodules ├── sample-projects └── shtc3-stm32-uvision │ ├── Source │ ├── system.c │ ├── system.h │ ├── main.c │ ├── sensirion_sw_i2c_implementation.c │ └── startup_stm32f10x_md_vl.s │ ├── images │ ├── shtc3.png │ ├── schematics.png │ ├── uvision-build.png │ ├── uvision-debug.png │ ├── uvision-run.png │ └── stm32-discovery.png │ ├── prepare_release.sh │ ├── copy_shtc1_driver.sh │ ├── README.md │ ├── .gitignore │ ├── LICENSE │ ├── RELEASE_DOC.md │ └── shtc3-stm32.uvprojx ├── .github ├── pull_request_template.md └── workflows │ └── check.yml ├── sht3x ├── Makefile ├── user_config.inc ├── default_config.inc ├── sht3x_example_usage.c ├── sht3x.h └── sht3x.c ├── sht4x ├── Makefile ├── user_config.inc ├── default_config.inc ├── sht4x_example_usage.c ├── sht4x.c └── sht4x.h ├── shtc1 ├── Makefile ├── user_config.inc ├── default_config.inc ├── shtc1_example_usage.c ├── shtc1.c └── shtc1.h ├── .clang-format ├── .gitignore ├── utils ├── Makefile ├── default_config.inc ├── sensirion_temperature_unit_conversion.c ├── sensirion_humidity_conversion.h ├── sensirion_temperature_unit_conversion.h ├── sensirion_humidity_conversion.c └── ah_lut.py ├── LICENSE ├── sht-common └── sht_git_version.h ├── tests ├── Makefile ├── sht4x-test.cpp ├── sht3x-test.cpp └── shtc1-test.cpp ├── README.md ├── Makefile └── CHANGELOG.md /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "embedded-common"] 2 | path = embedded-common 3 | url = https://github.com/Sensirion/embedded-common 4 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/Source/system.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/Source/system.c -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/Source/system.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/Source/system.h -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/images/shtc3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/images/shtc3.png -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/images/schematics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/images/schematics.png -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/images/uvision-build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/images/uvision-build.png -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/images/uvision-debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/images/uvision-debug.png -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/images/uvision-run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/images/uvision-run.png -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/images/stm32-discovery.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sensirion/embedded-sht/HEAD/sample-projects/shtc3-stm32-uvision/images/stm32-discovery.png -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Check the following: 2 | 3 | - [ ] Breaking changes marked in commit message 4 | - [ ] Changelog updated 5 | - [ ] Code style cleaned (ran `make style-fix`) 6 | - [ ] Tested on actual hardware 7 | -------------------------------------------------------------------------------- /sht3x/Makefile: -------------------------------------------------------------------------------- 1 | # See user_config.inc for build customization 2 | -include user_config.inc 3 | include default_config.inc 4 | 5 | 6 | .PHONY: all clean 7 | 8 | all: sht3x_example_usage 9 | 10 | sht3x_example_usage: clean 11 | $(CC) $(CFLAGS) -o $@ ${sht3x_sources} ${${CONFIG_I2C_TYPE}_sources} ${sht3x_dir}/sht3x_example_usage.c 12 | 13 | clean: 14 | $(RM) sht3x_example_usage 15 | -------------------------------------------------------------------------------- /sht4x/Makefile: -------------------------------------------------------------------------------- 1 | # See user_config.inc for build customization 2 | -include user_config.inc 3 | include default_config.inc 4 | 5 | 6 | .PHONY: all clean 7 | 8 | all: sht4x_example_usage 9 | 10 | sht4x_example_usage: clean 11 | $(CC) $(CFLAGS) -o $@ ${sht4x_sources} ${${CONFIG_I2C_TYPE}_sources} ${sht4x_dir}/sht4x_example_usage.c 12 | 13 | clean: 14 | $(RM) sht4x_example_usage 15 | -------------------------------------------------------------------------------- /shtc1/Makefile: -------------------------------------------------------------------------------- 1 | # See user_config.inc for build customization 2 | -include user_config.inc 3 | include default_config.inc 4 | 5 | 6 | .PHONY: all clean 7 | 8 | all: shtc1_example_usage 9 | 10 | shtc1_example_usage: clean 11 | $(CC) $(CFLAGS) -o $@ ${shtc1_sources} ${${CONFIG_I2C_TYPE}_sources} ${shtc1_dir}/shtc1_example_usage.c 12 | 13 | clean: 14 | $(RM) shtc1_example_usage 15 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | IndentWidth: 4 5 | AlignAfterOpenBracket: Align 6 | AllowShortBlocksOnASingleLine: false 7 | AllowShortCaseLabelsOnASingleLine: false 8 | AllowShortFunctionsOnASingleLine: false 9 | IndentCaseLabels: true 10 | SpacesBeforeTrailingComments: 2 11 | PointerAlignment: Left 12 | AlignEscapedNewlines: Left 13 | ForEachMacros: ['TEST_GROUP', 'TEST'] 14 | ... 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | /release 3 | /sht3x/sht3x_example_usage 4 | /sht3x/user_config.inc 5 | /sht4x/sht4x_example_usage 6 | /sht4x/user_config.inc 7 | /shtc1/shtc1_example_usage 8 | /shtc1/user_config.inc 9 | /sht-common/sht_git_version.c 10 | i2c-mux-testbed/ 11 | tests/sht3x-test-hw_i2c 12 | tests/sht3x-test-sw_i2c 13 | tests/sht4x-test-hw_i2c 14 | tests/sht4x-test-sw_i2c 15 | tests/shtc1-test-hw_i2c 16 | tests/shtc1-test-sw_i2c 17 | 18 | -------------------------------------------------------------------------------- /utils/Makefile: -------------------------------------------------------------------------------- 1 | include default_config.inc 2 | 3 | .PHONY: clean 4 | 5 | obj = sensirion_temperature_unit_conversion.o \ 6 | sensirion_humidity_conversion.o 7 | 8 | all: $(obj) 9 | 10 | sensirion_temperature_unit_conversion.o: $(sensirion_temperature_unit_conversion_sources) 11 | $(CC) $(CFLAGS) -shared -o $@ $< 12 | 13 | sensirion_humidity_conversion.o: $(sensirion_humidity_conversion_sources) 14 | $(CC) $(CFLAGS) -shared -o $@ $< 15 | 16 | clean: 17 | $(RM) $(obj) 18 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/prepare_release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$#" -ne 1 ] || ! [ -d "$1" ]; then 4 | echo "Usage: $0 OUTPUT_DIRECTORY" >&2 5 | exit 1 6 | fi 7 | 8 | BASE_DIR=$(dirname "$0") 9 | 10 | "${BASE_DIR}/copy_shtc1_driver.sh" 11 | 12 | # Copy everything 13 | cp -r "${BASE_DIR}/"* "$1" 14 | # Create documentation 15 | (cd "$1" && pandoc --variable urlcolor=cyan -s -o README.pdf RELEASE_DOC.md) 16 | # Delete unneeded files 17 | rm "$1"/copy_shtc1_driver.sh 18 | rm "$1"/prepare_release.sh 19 | rm "$1"/README.md 20 | rm "$1"/RELEASE_DOC.md 21 | -------------------------------------------------------------------------------- /utils/default_config.inc: -------------------------------------------------------------------------------- 1 | sht_driver_dir ?= .. 2 | sensirion_common_dir ?= ${sht_driver_dir}/embedded-common 3 | sht_utils_dir ?= ${sht_driver_dir}/utils 4 | 5 | CFLAGS ?= -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC 6 | CFLAGS += -I${sht_utils_dir} -I${sensirion_common_dir} 7 | 8 | sensirion_humidity_conversion_sources = \ 9 | ${sht_utils_dir}/sensirion_humidity_conversion.h \ 10 | ${sht_utils_dir}/sensirion_humidity_conversion.c 11 | 12 | sensirion_temperature_unit_conversion_sources = \ 13 | ${sht_utils_dir}/sensirion_temperature_unit_conversion.h \ 14 | ${sht_utils_dir}/sensirion_temperature_unit_conversion.c 15 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/copy_shtc1_driver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -euo pipefail 4 | 5 | BASE_DIR=$(dirname "$0") 6 | 7 | mkdir -p "$BASE_DIR"/shtc1/sw_i2c 8 | cp "$BASE_DIR/../../embedded-common/"*.[ch] "$BASE_DIR"/shtc1/ 9 | cp "$BASE_DIR/../../embedded-common/sw_i2c/"*.[ch] "$BASE_DIR"/shtc1/sw_i2c/ 10 | cp "$BASE_DIR/../../shtc1/shtc1."[ch] "$BASE_DIR"/shtc1/ 11 | cp "$BASE_DIR/../../sht-common/sht_git_version.h" "$BASE_DIR"/shtc1/ 12 | gitversion=$(git describe --always --dirty) 13 | cat << EOF > "$BASE_DIR/shtc1/sht_git_version.c" 14 | /* THIS FILE IS AUTOGENERATED */ 15 | #include "sht_git_version.h" 16 | const char * SHT_DRV_VERSION_STR = "$gitversion"; 17 | EOF 18 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/README.md: -------------------------------------------------------------------------------- 1 | # SHTC3 Sample Code for STM32 2 | 3 | This uVision sample project shows the basic usage of Sensirion's SHTC3 4 | temperature and humidity sensor. 5 | 6 | ## Compatibility 7 | The code herein is compatible with Sensirion's SHTC3 digital temperature and 8 | humidity sensor. 9 | 10 | * Sensirion SHTC3 Sensor 11 | * STM32 Discovery board ([STM32VLDISCOVERY]) 12 | * uVision (5.25) 13 | 14 | ## Introduction 15 | 16 | Sensirion's developer page 17 | [developer.sensirion.com](https://developer.sensirion.com) provides more 18 | developer resources for different platforms and products. 19 | 20 | ## Cloning this Repository 21 | 22 | ``` 23 | git clone --recursive https://github.com/Sensirion/embedded-sht.git 24 | ``` 25 | 26 | ## Building from the repository 27 | 28 | If you cloned the repository, prior to building the project you need to execute 29 | the following script in Git Bash: 30 | 31 | ```bash 32 | ./copy_shtc1_driver.sh 33 | ``` 34 | 35 | [STM32VLDISCOVERY]: https://www.st.com/en/evaluation-tools/stm32vldiscovery.html 36 | -------------------------------------------------------------------------------- /sht3x/user_config.inc: -------------------------------------------------------------------------------- 1 | ## This file controls the custom user build settings. 2 | 3 | ## Choose either of hw_i2c or sw_i2c depending on whether you have a dedicated 4 | ## i2c controller (hw_i2c) or are using bit-banging on GPIOs (sw_i2c) 5 | # CONFIG_I2C_TYPE = hw_i2c 6 | 7 | ## For hw_i2c, configure the i2c HAL implementation to use. 8 | ## Use one of the available sample-implementations or implement your own using 9 | ## the stub. 10 | # hw_i2c_impl_src = ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c 11 | 12 | ## For sw_i2c, configure the GPIO implementation. 13 | # sw_i2c_impl_src = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c 14 | 15 | ## 16 | ## The items below are listed as documentation but may not need customization 17 | ## 18 | 19 | ## The build paths can also be changed here if needed 20 | # sht_driver_dir = .. 21 | # sensirion_common_dir = ${sht_driver_dir}/embedded-common 22 | # sht_common_dir = ${sht_driver_dir}/sht-common 23 | # sht3x_dir = ${sht_driver_dir}/sht3x 24 | 25 | ## If you need different CFLAGS, those can be customized as well 26 | # CFLAGS = -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC 27 | -------------------------------------------------------------------------------- /sht4x/user_config.inc: -------------------------------------------------------------------------------- 1 | ## This file controls the custom user build settings. 2 | 3 | ## Choose either of hw_i2c or sw_i2c depending on whether you have a dedicated 4 | ## i2c controller (hw_i2c) or are using bit-banging on GPIOs (sw_i2c) 5 | # CONFIG_I2C_TYPE = hw_i2c 6 | 7 | ## For hw_i2c, configure the i2c HAL implementation to use. 8 | ## Use one of the available sample-implementations or implement your own using 9 | ## the stub. 10 | # hw_i2c_impl_src = ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c 11 | 12 | ## For sw_i2c, configure the GPIO implementation. 13 | # sw_i2c_impl_src = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c 14 | 15 | ## 16 | ## The items below are listed as documentation but may not need customization 17 | ## 18 | 19 | ## The build paths can also be changed here if needed 20 | # sht_driver_dir = .. 21 | # sensirion_common_dir = ${sht_driver_dir}/embedded-common 22 | # sht_common_dir = ${sht_driver_dir}/sht-common 23 | # sht4x_dir = ${sht_driver_dir}/sht4x 24 | 25 | ## If you need different CFLAGS, those can be customized as well 26 | # CFLAGS = -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC 27 | -------------------------------------------------------------------------------- /shtc1/user_config.inc: -------------------------------------------------------------------------------- 1 | ## This file controls the custom user build settings. 2 | 3 | ## Choose either of hw_i2c or sw_i2c depending on whether you have a dedicated 4 | ## i2c controller (hw_i2c) or are using bit-banging on GPIOs (sw_i2c) 5 | # CONFIG_I2C_TYPE = hw_i2c 6 | 7 | ## For hw_i2c, configure the i2c HAL implementation to use. 8 | ## Use one of the available sample-implementations or implement your own using 9 | ## the stub. 10 | # hw_i2c_impl_src = ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c 11 | 12 | ## For sw_i2c, configure the GPIO implementation. 13 | # sw_i2c_impl_src = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c 14 | 15 | ## 16 | ## The items below are listed as documentation but may not need customization 17 | ## 18 | 19 | ## The build paths can also be changed here if needed 20 | # sht_driver_dir = .. 21 | # sensirion_common_dir = ${sht_driver_dir}/embedded-common 22 | # sht_common_dir = ${sht_driver_dir}/sht-common 23 | # shtc1_dir = ${sht_driver_dir}/shtc1 24 | 25 | ## If you need different CFLAGS, those can be customized as well 26 | # CFLAGS = -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC 27 | -------------------------------------------------------------------------------- /.github/workflows/check.yml: -------------------------------------------------------------------------------- 1 | name: syntax, static code analyis and build check for c drivers 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | push: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | code-analysis: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v4 16 | - uses: awalsh128/cache-apt-pkgs-action@v1 17 | with: 18 | packages: cppcheck clang-format 19 | version: 1.0 20 | - name: clang-format syntax-check 21 | run: | 22 | find sht-common -type f -iregex ".*\.\(c\|h\|cpp\|ino\)" -exec clang-format -i -style=file {} \; 23 | find shtc1 -type f -iregex ".*\.\(c\|h\|cpp\|ino\)" -exec clang-format -i -style=file {} \; 24 | find sht3x -type f -iregex ".*\.\(c\|h\|cpp\|ino\)" -exec clang-format -i -style=file {} \; 25 | find sht4x -type f -iregex ".*\.\(c\|h\|cpp\|ino\)" -exec clang-format -i -style=file {} \; 26 | git diff --exit-code 27 | - name: cppcheck static code analyis 28 | run: cppcheck --std=c89 --language=c --error-exitcode=1 --enable=warning,style,performance,portability --suppress=unreadVariable -i sample-projects/ -i embedded-common/ -i release/ . 29 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/.gitignore: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/mrshrdlu/gitignore-keil/blob/master/keil.gitignore 2 | 3 | # A .gitignore for Keil projects. 4 | # Taken mostly from http://www.keil.com/support/man/docs/uv4/uv4_b_filetypes.htm 5 | 6 | # User-specific uVision files 7 | *.opt 8 | *.uvopt 9 | *.uvoptx 10 | *.uvgui 11 | *.uvgui.* 12 | *.uvguix.* 13 | 14 | # Listing files 15 | *.cod 16 | *.htm 17 | *.i 18 | *.lst 19 | *.map 20 | *.m51 21 | *.m66 22 | *.scr # define exception below if needed 23 | 24 | # Object and HEX files 25 | *.axf 26 | *.b[0-3][0-9] 27 | *.hex 28 | *.d 29 | *.crf 30 | *.elf 31 | *.hex 32 | *.h86 33 | *.lib 34 | *.obj 35 | *.o 36 | *.sbr 37 | 38 | # Build files 39 | *.bat # define exception below if needed 40 | *._ia 41 | *.__i 42 | *._ii 43 | 44 | # Debugger files 45 | *.ini # define exception below if needed 46 | 47 | # Other files 48 | *.build_log.htm 49 | *.cdb 50 | *.dep 51 | *.ic 52 | *.lin 53 | *.lnp 54 | *.orc 55 | *.pack # define exception below if needed 56 | *.pdsc # define exception below if needed 57 | *.plg 58 | *.sct # define exception below if needed 59 | *.sfd 60 | *.sfr 61 | *.svcd 62 | 63 | # Miscellaneous 64 | *.tra 65 | *.bin 66 | *.fed 67 | *.l1p 68 | *.l2p 69 | *.iex 70 | 71 | *.scvd 72 | DebugConfig/ 73 | RTE/ 74 | Objects/ 75 | shtc1/ 76 | -------------------------------------------------------------------------------- /sht3x/default_config.inc: -------------------------------------------------------------------------------- 1 | sht_driver_dir ?= .. 2 | sensirion_common_dir ?= ${sht_driver_dir}/embedded-common 3 | sht_common_dir ?= ${sht_driver_dir}/sht-common 4 | sht3x_dir ?= ${sht_driver_dir}/sht3x 5 | CONFIG_I2C_TYPE ?= hw_i2c 6 | 7 | sw_i2c_impl_src ?= ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c 8 | hw_i2c_impl_src ?= ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c 9 | 10 | CFLAGS ?= -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC 11 | CFLAGS += -I${sensirion_common_dir} -I${sht_common_dir} -I${sht3x_dir} \ 12 | -I${sensirion_common_dir}/${CONFIG_I2C_TYPE} 13 | 14 | sensirion_common_sources = ${sensirion_common_dir}/sensirion_arch_config.h \ 15 | ${sensirion_common_dir}/sensirion_i2c.h \ 16 | ${sensirion_common_dir}/sensirion_common.h \ 17 | ${sensirion_common_dir}/sensirion_common.c 18 | 19 | sht_common_sources = ${sht_common_dir}/sht_git_version.h \ 20 | ${sht_common_dir}/sht_git_version.c 21 | 22 | sht3x_sources = ${sensirion_common_sources} ${sht_common_sources} \ 23 | ${sht3x_dir}/sht3x.h ${sht3x_dir}/sht3x.c 24 | 25 | hw_i2c_sources = ${hw_i2c_impl_src} 26 | sw_i2c_sources = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_gpio.h \ 27 | ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c.c \ 28 | ${sw_i2c_impl_src} 29 | -------------------------------------------------------------------------------- /sht4x/default_config.inc: -------------------------------------------------------------------------------- 1 | sht_driver_dir ?= .. 2 | sensirion_common_dir ?= ${sht_driver_dir}/embedded-common 3 | sht_common_dir ?= ${sht_driver_dir}/sht-common 4 | sht4x_dir ?= ${sht_driver_dir}/sht4x 5 | CONFIG_I2C_TYPE ?= hw_i2c 6 | 7 | sw_i2c_impl_src ?= ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c 8 | hw_i2c_impl_src ?= ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c 9 | 10 | CFLAGS ?= -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC 11 | CFLAGS += -I${sensirion_common_dir} -I${sht_common_dir} -I${sht4x_dir} \ 12 | -I${sensirion_common_dir}/${CONFIG_I2C_TYPE} 13 | 14 | sensirion_common_sources = ${sensirion_common_dir}/sensirion_arch_config.h \ 15 | ${sensirion_common_dir}/sensirion_i2c.h \ 16 | ${sensirion_common_dir}/sensirion_common.h \ 17 | ${sensirion_common_dir}/sensirion_common.c 18 | 19 | sht_common_sources = ${sht_common_dir}/sht_git_version.h \ 20 | ${sht_common_dir}/sht_git_version.c 21 | 22 | sht4x_sources = ${sensirion_common_sources} ${sht_common_sources} \ 23 | ${sht4x_dir}/sht4x.h ${sht4x_dir}/sht4x.c 24 | 25 | hw_i2c_sources = ${hw_i2c_impl_src} 26 | sw_i2c_sources = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_gpio.h \ 27 | ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c.c \ 28 | ${sw_i2c_impl_src} 29 | -------------------------------------------------------------------------------- /shtc1/default_config.inc: -------------------------------------------------------------------------------- 1 | sht_driver_dir ?= .. 2 | sensirion_common_dir ?= ${sht_driver_dir}/embedded-common 3 | sht_common_dir ?= ${sht_driver_dir}/sht-common 4 | shtc1_dir ?= ${sht_driver_dir}/shtc1 5 | CONFIG_I2C_TYPE ?= hw_i2c 6 | 7 | sw_i2c_impl_src ?= ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_implementation.c 8 | hw_i2c_impl_src ?= ${sensirion_common_dir}/hw_i2c/sensirion_hw_i2c_implementation.c 9 | 10 | CFLAGS ?= -Os -Wall -fstrict-aliasing -Wstrict-aliasing=1 -Wsign-conversion -fPIC 11 | CFLAGS += -I${sensirion_common_dir} -I${sht_common_dir} -I${shtc1_dir} \ 12 | -I${sensirion_common_dir}/${CONFIG_I2C_TYPE} 13 | 14 | sensirion_common_sources = ${sensirion_common_dir}/sensirion_arch_config.h \ 15 | ${sensirion_common_dir}/sensirion_i2c.h \ 16 | ${sensirion_common_dir}/sensirion_common.h \ 17 | ${sensirion_common_dir}/sensirion_common.c 18 | 19 | sht_common_sources = ${sht_common_dir}/sht_git_version.h \ 20 | ${sht_common_dir}/sht_git_version.c 21 | 22 | shtc1_sources = ${sensirion_common_sources} ${sht_common_sources} \ 23 | ${shtc1_dir}/shtc1.h ${shtc1_dir}/shtc1.c 24 | 25 | hw_i2c_sources = ${hw_i2c_impl_src} 26 | sw_i2c_sources = ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c_gpio.h \ 27 | ${sensirion_common_dir}/sw_i2c/sensirion_sw_i2c.c \ 28 | ${sw_i2c_impl_src} 29 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Sensirion AG 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Sensirion AG nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Sensirion AG 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /sht-common/sht_git_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef SHT_GIT_VERSION_H 33 | #define SHT_GIT_VERSION_H 34 | 35 | extern const char* SHT_DRV_VERSION_STR; 36 | 37 | #endif /* SHT_GIT_VERSION_H */ 38 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | include ../embedded-common/test-config/base_config.inc 2 | sht_driver_dir := ${driver_dir}/embedded-sht 3 | include ${sht_driver_dir}/sht3x/default_config.inc 4 | include ${sht_driver_dir}/sht4x/default_config.inc 5 | include ${sht_driver_dir}/shtc1/default_config.inc 6 | 7 | sht3x_test_binaries := sht3x-test-hw_i2c sht3x-test-sw_i2c 8 | sht4x_test_binaries := sht4x-test-hw_i2c sht4x-test-sw_i2c 9 | shtc1_test_binaries := shtc1-test-hw_i2c shtc1-test-sw_i2c 10 | 11 | .PHONY: all clean prepare test 12 | 13 | all: clean prepare test 14 | 15 | prepare: 16 | cd ${sht_driver_dir} && $(MAKE) prepare 17 | 18 | sht3x-test-hw_i2c: CONFIG_I2C_TYPE := hw_i2c 19 | sht3x-test-hw_i2c: sht3x-test.cpp ${sht3x_sources} ${hw_i2c_sources} ${sensirion_test_sources} 20 | $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) 21 | 22 | sht3x-test-sw_i2c: CONFIG_I2C_TYPE := sw_i2c 23 | sht3x-test-sw_i2c: sht3x-test.cpp ${sht3x_sources} ${sw_i2c_sources} ${sensirion_test_sources} 24 | $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) 25 | 26 | sht4x-test-hw_i2c: CONFIG_I2C_TYPE := hw_i2c 27 | sht4x-test-hw_i2c: sht4x-test.cpp ${sht4x_sources} ${hw_i2c_sources} ${sensirion_test_sources} 28 | $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) 29 | 30 | sht4x-test-sw_i2c: CONFIG_I2C_TYPE := sw_i2c 31 | sht4x-test-sw_i2c: sht4x-test.cpp ${sht4x_sources} ${sw_i2c_sources} ${sensirion_test_sources} 32 | $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) 33 | 34 | shtc1-test-hw_i2c: CONFIG_I2C_TYPE := hw_i2c 35 | shtc1-test-hw_i2c: shtc1-test.cpp ${shtc1_sources} ${hw_i2c_sources} ${sensirion_test_sources} 36 | $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) 37 | 38 | shtc1-test-sw_i2c: CONFIG_I2C_TYPE := sw_i2c 39 | shtc1-test-sw_i2c: shtc1-test.cpp ${shtc1_sources} ${sw_i2c_sources} ${sensirion_test_sources} 40 | $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) 41 | 42 | clean: 43 | $(RM) ${sht4x_test_binaries} ${sht3x_test_binaries} ${shtc1_test_binaries} 44 | 45 | test: prepare ${sht4x_test_binaries} ${sht3x_test_binaries} ${shtc1_test_binaries} 46 | set -ex; for test in ${sht3x_test_binaries}; do echo $${test}; ./$${test}; echo; done; 47 | set -ex; for test in ${sht4x_test_binaries}; do echo $${test}; ./$${test}; echo; done; 48 | set -ex; for test in ${shtc1_test_binaries}; do echo $${test}; ./$${test}; echo; done; 49 | -------------------------------------------------------------------------------- /tests/sht4x-test.cpp: -------------------------------------------------------------------------------- 1 | #include "sensirion_common.h" 2 | #include "sensirion_test_setup.h" 3 | #include "sht4x.h" 4 | 5 | static void sht4x_run_test() { 6 | int16_t ret; 7 | int32_t temperature; 8 | int32_t humidity; 9 | uint32_t serial; 10 | 11 | ret = sht4x_measure_blocking_read(&temperature, &humidity); 12 | CHECK_ZERO_TEXT(ret, "sht4x_measure_blocking_read"); 13 | CHECK_TRUE_TEXT(temperature >= 5000 && temperature <= 45000, 14 | "sht4x_measure_blocking_read temperature"); 15 | CHECK_TRUE_TEXT(humidity >= 0 && humidity <= 100000, 16 | "sht4x_measure_blocking_read humidity"); 17 | 18 | ret = sht4x_measure(); 19 | CHECK_ZERO_TEXT(ret, "sht4x_measure"); 20 | 21 | sensirion_sleep_usec(SHT4X_MEASUREMENT_DURATION_USEC); 22 | 23 | ret = sht4x_read(&temperature, &humidity); 24 | CHECK_ZERO_TEXT(ret, "sht4x_read"); 25 | CHECK_TRUE_TEXT(temperature >= 5000 && temperature <= 45000, 26 | "sht4x_read temperature"); 27 | CHECK_TRUE_TEXT(humidity >= 0 && humidity <= 100000, "sht4x_read humidity"); 28 | 29 | ret = sht4x_read_serial(&serial); 30 | CHECK_ZERO_TEXT(ret, "sht4x_read_serial"); 31 | printf("SHT4X serial: %u\n", serial); 32 | 33 | const char* version = sht4x_get_driver_version(); 34 | printf("sht4x_get_driver_version: %s\n", version); 35 | 36 | uint8_t addr = sht4x_get_configured_address(); 37 | CHECK_EQUAL_TEXT(0x44, addr, "sht4x_get_configured_address"); 38 | } 39 | 40 | static void sht4x_test_all_power_modes() { 41 | int16_t ret = sht4x_probe(); 42 | CHECK_ZERO_TEXT(ret, "sht4x_probe"); 43 | 44 | printf("Running tests in normal mode...\n"); 45 | sht4x_run_test(); 46 | 47 | printf("Running tests in low power mode...\n"); 48 | sht4x_enable_low_power_mode(1); 49 | sht4x_run_test(); 50 | } 51 | 52 | static void test_teardown() { 53 | int16_t ret = sensirion_i2c_general_call_reset(); 54 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_general_call_reset"); 55 | sensirion_i2c_release(); 56 | } 57 | 58 | TEST_GROUP (SHT4X_Tests) { 59 | void setup() { 60 | sensirion_i2c_init(); 61 | int16_t ret = sensirion_i2c_mux_set_single_channel(0x71, 7); 62 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_mux_select_TEXT(0x71, 7)"); 63 | } 64 | 65 | void teardown() { 66 | test_teardown(); 67 | } 68 | }; 69 | 70 | TEST (SHT4X_Tests, SHT4XTest) { sht4x_test_all_power_modes(); } 71 | -------------------------------------------------------------------------------- /tests/sht3x-test.cpp: -------------------------------------------------------------------------------- 1 | #include "sensirion_common.h" 2 | #include "sensirion_test_setup.h" 3 | #include "sht3x.h" 4 | 5 | static void sht3x_run_test() { 6 | int16_t ret; 7 | int32_t temperature; 8 | int32_t humidity; 9 | uint32_t serial; 10 | 11 | ret = sht3x_measure_blocking_read(SHT3X_I2C_ADDR_DFLT, &temperature, 12 | &humidity); 13 | CHECK_ZERO_TEXT(ret, "sht3x_measure_blocking_read"); 14 | CHECK_TRUE_TEXT(temperature >= 5000 && temperature <= 45000, 15 | "sht3x_measure_blocking_read temperature"); 16 | CHECK_TRUE_TEXT(humidity >= 0 && humidity <= 100000, 17 | "sht3x_measure_blocking_read humidity"); 18 | 19 | ret = sht3x_measure(SHT3X_I2C_ADDR_DFLT); 20 | CHECK_ZERO_TEXT(ret, "sht3x_measure"); 21 | 22 | sensirion_sleep_usec(SHT3X_MEASUREMENT_DURATION_USEC); 23 | 24 | ret = sht3x_read(SHT3X_I2C_ADDR_DFLT, &temperature, &humidity); 25 | CHECK_ZERO_TEXT(ret, "sht3x_read"); 26 | CHECK_TRUE_TEXT(temperature >= 5000 && temperature <= 45000, 27 | "sht3x_read temperature"); 28 | CHECK_TRUE_TEXT(humidity >= 0 && humidity <= 100000, "sht3x_read humidity"); 29 | 30 | ret = sht3x_read_serial(SHT3X_I2C_ADDR_DFLT, &serial); 31 | CHECK_ZERO_TEXT(ret, "sht3x_read_serial"); 32 | printf("SHT3X serial: %u\n", serial); 33 | 34 | const char* version = sht3x_get_driver_version(); 35 | printf("sht3x_get_driver_version: %s\n", version); 36 | } 37 | 38 | static void sht3x_test_all_power_modes() { 39 | int16_t ret = sht3x_probe(SHT3X_I2C_ADDR_DFLT); 40 | CHECK_ZERO_TEXT(ret, "sht3x_probe"); 41 | 42 | printf("Running tests in normal mode...\n"); 43 | sht3x_run_test(); 44 | 45 | printf("Running tests in low power mode...\n"); 46 | sht3x_enable_low_power_mode(1); 47 | sht3x_run_test(); 48 | } 49 | 50 | static void test_teardown() { 51 | int16_t ret = sensirion_i2c_general_call_reset(); 52 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_general_call_reset"); 53 | sensirion_i2c_release(); 54 | } 55 | 56 | TEST_GROUP (SHT31_Tests) { 57 | void setup() { 58 | sensirion_i2c_init(); 59 | int16_t ret = sensirion_i2c_mux_set_single_channel(0x72, 1); 60 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_mux_select_TEXT(0x72, 1)"); 61 | } 62 | 63 | void teardown() { 64 | test_teardown(); 65 | } 66 | }; 67 | 68 | TEST (SHT31_Tests, SHT31Test) { sht3x_test_all_power_modes(); } 69 | -------------------------------------------------------------------------------- /utils/sensirion_temperature_unit_conversion.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include "sensirion_temperature_unit_conversion.h" 33 | 34 | int32_t sensirion_celsius_to_fahrenheit(int32_t temperature_milli_celsius) { 35 | /* Conversion equivalent to: temperature_milli_celsius * 9.0/5.0 + 32000 36 | * Fixed Point: 9.0/5.0 * 2^12 = 7372.8 37 | * Using int32_t sized two's complement for negatives */ 38 | return ((temperature_milli_celsius * 7373) >> 12) + 32000; 39 | } 40 | 41 | int32_t sensirion_fahrenheit_to_celsius(int32_t temperature_milli_fahrenheit) { 42 | /* Conversion equivalent to: 43 | * (temperature_milli_fahrenheit - 32000) * 5.0/9.0 44 | * Fixed Point: 5.0/9.0 * 2^10 = 568.9 45 | * Using int32_t sized two's complement for negatives */ 46 | return ((temperature_milli_fahrenheit - 32000) * 569) >> 10; 47 | } 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # embedded-sht [![CircleCI](https://circleci.com/gh/Sensirion/embedded-sht.svg?style=shield)](https://circleci.com/gh/Sensirion/embedded-sht) [![GitHub license](https://img.shields.io/badge/license-BSD3-blue.svg)](https://raw.githubusercontent.com/Sensirion/embedded-sht/master/LICENSE) 2 | This repository contains the embedded driver sources for Sensirion's 3 | SHT product line. 4 | 5 | ## Download the Latest Driver Release 6 | **Download the latest ready-to-use driver bundle from the [releases 7 | page](https://github.com/Sensirion/embedded-sht/releases/)** 8 | 9 | We strongly recommend to use the driver from the release bundle instead of 10 | cloning the repository. 11 | 12 | ## Clone this repository 13 | ``` 14 | git clone --recursive https://github.com/Sensirion/embedded-sht.git 15 | ``` 16 | 17 | ## Repository content 18 | * `embedded-common` submodule repository for the common embedded driver HAL 19 | * `sht-common` common files for all SHTxx drivers, humidity conversion functions 20 | * `sht4x` SHT4 driver 21 | * `sht3x` SHT3x/SHT8x driver 22 | * `shtc1` SHTC3/SHTC1/SHTW1/SHTW2 driver 23 | * `utils` Conversion functions (Centigrade to Fahrenheit, %RH relative humidity 24 | to aboslute humidity) 25 | 26 | For sht3x and sht4x there are also updated drivers available in separate repositories. 27 | 28 | ## Collecting resources 29 | ``` 30 | make release 31 | ``` 32 | This will create the `release` folder with the necessary driver files in it, 33 | including a Makefile. That way, you have just ONE folder with all the sources 34 | ready to build your driver for your platform. 35 | 36 | ## Files to adjust (from embedded-common) 37 | You only need to touch the following files: 38 | 39 | * `sensirion_arch_config.h` (architecture specifics, you need to specify 40 | the integer sizes) 41 | 42 | and depending on your i2c implementation either of the following: 43 | 44 | * `embedded-common/hw_i2c/sensirion_hw_i2c_implementation.c` 45 | functions for hardware i2c communication if your platform supports that 46 | * `embedded-common/sw_i2c/sensirion_sw_i2c_implementation.c` 47 | functions for software i2c communication via GPIOs 48 | 49 | ## Building the driver 50 | 1. Adjust `sensirion_arch_config.h` if you don't have the `` header 51 | file available 52 | 2. Implement necessary functions in one of the `*_implementation.c` files 53 | described above 54 | 3. make 55 | 56 | --- 57 | 58 | Please check the [embedded-common](https://github.com/Sensirion/embedded-common) 59 | repository for further information and sample implementations. 60 | 61 | --- 62 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/RELEASE_DOC.md: -------------------------------------------------------------------------------- 1 | # SHTC3 Sample Code for STM32 2 | 3 | This uVision sample project shows the basic usage of Sensirion's SHTC3 4 | temperature and humidity sensor. 5 | 6 | ![SHTC3](images/shtc3.png) 7 | ![STM32VLDISCOVERY](images/stm32-discovery.png) 8 | 9 | ## Compatibility 10 | 11 | The code herein is compatible with Sensirion's SHTC3 digital temperature and 12 | humidity sensor. 13 | 14 | * Sensirion SHTC3 Sensor 15 | * STM32 Discovery board ([STM32VLDISCOVERY]) 16 | * uVision (5.25) 17 | 18 | ## System Requirements 19 | 20 | * Windows PC 21 | * SHTC3 Sensor 22 | * STM32-Discovery board from STMicroelectronics ([STM32VLDISCOVERY]) 23 | * USB type A to mini-B cable 24 | 25 | ## Getting Started 26 | 27 | 1. Download the latest version of Microcontroller Development Kit for ARM 28 | (MDK-ARM). The software can be used without a product license for a maximum 29 | code size of 32 Kbytes. 30 | *Tested Version: 5.25* 31 | 2. Run the Installer and follow the instructions. (MDK525.EXE) 32 | 3. Open the project file `shtc3-stm32.uvprojx`. 33 | 4. Press F7 or click ![build target icon](images/uvision-build.png) to build 34 | the target. 35 | 5. Connect the SHTC3 Sensor to the STM32-Discovery board: 36 | 37 | |Discovery board|SHTC3-Sensor| 38 | |---------------|------------| 39 | | 3V3 | VDD | 40 | | BP8 | SCL | 41 | | BP9 | SDA | 42 | | GND | GND | 43 | Also connect pull-up resistors (e.g. 10kOhm) from SCL and SDA to VDD and 44 | add a decoupling capacitor between VDD and GND. 45 | 46 | ![Typical application circuit](images/schematics.png) 47 | 48 | 6. Connect the STM32-Discovery board to the PC with the USB cable. 49 | 7. Start the debugger by pressing Ctrl+F5 or click Debug in the menu → 50 | Start/Stop Debug Session ![Debug icon](images/uvision-debug.png). 51 | 8. Press F5 or click ![the run program icon](images/uvision-run.png) to run the 52 | program. 53 | The green LED lights if no error occurs, in this case the communication 54 | with the sensor works. The blue LED lights up when a relative humidity of 55 | more than 50% is measured. You can simulate this by breathing on the 56 | sensor. 57 | 9. Add the variables error, id, temperature, and humidity to the watcher or 58 | set a breakpoint to check the values. 59 | 60 | ## Further Information 61 | 62 | Sensirion's developer page 63 | [developer.sensirion.com](https://developer.sensirion.com) provides more 64 | developer resources for different platforms and products. 65 | Also the [SHTC3 product page](https://www.sensirion.com/shtc3/) has more 66 | detailed information about the sensor. 67 | 68 | [STM32VLDISCOVERY]: https://www.st.com/en/evaluation-tools/stm32vldiscovery.html 69 | -------------------------------------------------------------------------------- /utils/sensirion_humidity_conversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef HUMIDITY_CONVERSION_H 33 | #define HUMIDITY_CONVERSION_H 34 | #include "sensirion_arch_config.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** 41 | * sensirion_calc_absolute_humidity() - Calculate absolute humidity from 42 | * temperature and relative humidity 43 | * 44 | * @param temperature_milli_celsius The temperature measurement in milli Degree 45 | * Celsius, i.e. degree celsius multiplied by 46 | * 1000. 47 | * @param humidity_milli_percent The relative humidity measurement in 48 | * milli Percent, i.e. percent relative 49 | * humidity, multiplied by 1000 (0-100000) 50 | * 51 | * @return The absolute humidity in mg/m^3 52 | */ 53 | uint32_t sensirion_calc_absolute_humidity(int32_t temperature_milli_celsius, 54 | int32_t humidity_milli_percent); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif /* HUMIDITY_CONVERSION_H */ 61 | -------------------------------------------------------------------------------- /shtc1/shtc1_example_usage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include // printf 33 | 34 | /* TO USE CONSOLE OUTPUT (printf) YOU MAY NEED TO ADAPT THE 35 | * INCLUDE ABOVE OR DEFINE IT ACCORDING TO YOUR PLATFORM. 36 | * #define printf(...) 37 | */ 38 | 39 | #include "shtc1.h" 40 | 41 | int main(void) { 42 | /* Initialize the i2c bus for the current platform */ 43 | sensirion_i2c_init(); 44 | 45 | /* Busy loop for initialization, because the main loop does not work without 46 | * a sensor. 47 | */ 48 | while (shtc1_probe() != STATUS_OK) { 49 | printf("SHT sensor probing failed\n"); 50 | } 51 | printf("SHT sensor probing successful\n"); 52 | 53 | while (1) { 54 | int32_t temperature, humidity; 55 | /* Measure temperature and relative humidity and store into variables 56 | * temperature, humidity (each output multiplied by 1000). 57 | */ 58 | int8_t ret = shtc1_measure_blocking_read(&temperature, &humidity); 59 | if (ret == STATUS_OK) { 60 | printf("measured temperature: %0.2f degreeCelsius, " 61 | "measured humidity: %0.2f percentRH\n", 62 | temperature / 1000.0f, humidity / 1000.0f); 63 | } else { 64 | printf("error reading measurement\n"); 65 | } 66 | 67 | sensirion_sleep_usec(1000000); 68 | } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /sht4x/sht4x_example_usage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include "sht4x.h" 33 | #include // printf 34 | 35 | /** 36 | * TO USE CONSOLE OUTPUT (PRINTF) AND WAIT (SLEEP) PLEASE ADAPT THEM TO YOUR 37 | * PLATFORM 38 | */ 39 | 40 | int main(void) { 41 | /* Initialize the i2c bus for the current platform */ 42 | sensirion_i2c_init(); 43 | 44 | /* Busy loop for initialization, because the main loop does not work without 45 | * a sensor. 46 | */ 47 | while (sht4x_probe() != STATUS_OK) { 48 | printf("SHT sensor probing failed\n"); 49 | sensirion_sleep_usec(1000000); /* sleep 1s */ 50 | } 51 | printf("SHT sensor probing successful\n"); 52 | 53 | while (1) { 54 | int32_t temperature, humidity; 55 | /* Measure temperature and relative humidity and store into variables 56 | * temperature, humidity (each output multiplied by 1000). 57 | */ 58 | int8_t ret = sht4x_measure_blocking_read(&temperature, &humidity); 59 | if (ret == STATUS_OK) { 60 | printf("measured temperature: %0.2f degreeCelsius, " 61 | "measured humidity: %0.2f percentRH\n", 62 | temperature / 1000.0f, humidity / 1000.0f); 63 | } else { 64 | printf("error reading measurement\n"); 65 | } 66 | 67 | sensirion_sleep_usec(1000000); /* sleep 1s */ 68 | } 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /sht3x/sht3x_example_usage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include // printf 33 | 34 | /* TO USE CONSOLE OUTPUT (printf) YOU MAY NEED TO ADAPT THE 35 | * INCLUDE ABOVE OR DEFINE IT ACCORDING TO YOUR PLATFORM. 36 | * #define printf(...) 37 | */ 38 | 39 | #include "sht3x.h" 40 | 41 | int main(void) { 42 | /* Initialize the i2c bus for the current platform */ 43 | sensirion_i2c_init(); 44 | 45 | /* Busy loop for initialization, because the main loop does not work without 46 | * a sensor. 47 | */ 48 | while (sht3x_probe(SHT3X_I2C_ADDR_DFLT) != STATUS_OK) { 49 | printf("SHT sensor probing failed\n"); 50 | } 51 | printf("SHT sensor probing successful\n"); 52 | 53 | while (1) { 54 | int32_t temperature, humidity; 55 | /* Measure temperature and relative humidity and store into variables 56 | * temperature, humidity (each output multiplied by 1000). 57 | */ 58 | int8_t ret = sht3x_measure_blocking_read(SHT3X_I2C_ADDR_DFLT, 59 | &temperature, &humidity); 60 | if (ret == STATUS_OK) { 61 | printf("measured temperature: %0.2f degreeCelsius, " 62 | "measured humidity: %0.2f percentRH\n", 63 | temperature / 1000.0f, humidity / 1000.0f); 64 | } else { 65 | printf("error reading measurement\n"); 66 | } 67 | 68 | sensirion_sleep_usec(1000000); 69 | } 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | drivers=sht3x sht4x shtc1 2 | sample-projects=shtc3-stm32-uvision 3 | clean_drivers=$(foreach d, $(drivers), clean_$(d)) 4 | release_drivers=$(foreach d, $(drivers), release/$(d)) 5 | release_sample_projects=$(foreach s, $(sample-projects), release/$(s)) 6 | 7 | .PHONY: FORCE all $(release_drivers) $(clean_drivers) style-check style-fix \ 8 | utils clean_utils 9 | 10 | all: prepare $(drivers) utils 11 | 12 | prepare: sht-common/sht_git_version.c 13 | 14 | $(drivers): prepare 15 | cd $@ && $(MAKE) $(MFLAGS) 16 | 17 | sht-common/sht_git_version.c: FORCE 18 | git describe --always --dirty | \ 19 | awk 'BEGIN \ 20 | {print "/* THIS FILE IS AUTOGENERATED */"} \ 21 | {print "#include \"sht_git_version.h\""} \ 22 | {print "const char * SHT_DRV_VERSION_STR = \"" $$0"\";"} \ 23 | END {}' > $@ || echo "Can't update version, not a git repository" 24 | 25 | 26 | $(release_drivers): sht-common/sht_git_version.c 27 | export rel=$@ && \ 28 | export driver=$${rel#release/} && \ 29 | export tag="$$(git describe --always --dirty)" && \ 30 | export pkgname="$${driver}-$${tag}" && \ 31 | export pkgdir="release/$${pkgname}" && \ 32 | rm -rf "$${pkgdir}" && mkdir -p "$${pkgdir}" && \ 33 | cp -r embedded-common/hw_i2c/ "$${pkgdir}" && \ 34 | cp -r embedded-common/sw_i2c/ "$${pkgdir}" && \ 35 | cp embedded-common/sensirion_arch_config.h "$${pkgdir}" && \ 36 | cp embedded-common/sensirion_common.c "$${pkgdir}" && \ 37 | cp embedded-common/sensirion_common.h "$${pkgdir}" && \ 38 | cp embedded-common/sensirion_i2c.h "$${pkgdir}" && \ 39 | cp -r sht-common/* "$${pkgdir}" && \ 40 | cp -r $${driver}/* "$${pkgdir}" && \ 41 | cp CHANGELOG.md LICENSE "$${pkgdir}" && \ 42 | echo 'sensirion_common_dir = .' >> $${pkgdir}/user_config.inc && \ 43 | echo 'sht_common_dir = .' >> $${pkgdir}/user_config.inc && \ 44 | echo "$${driver}_dir = ." >> $${pkgdir}/user_config.inc && \ 45 | cd "$${pkgdir}" && $(MAKE) $(MFLAGS) && $(MAKE) clean $(MFLAGS) && cd - && \ 46 | cd release && zip -r "$${pkgname}.zip" "$${pkgname}" && cd - && \ 47 | ln -sfn $${pkgname} $@ 48 | 49 | $(release_sample_projects): 50 | export rel=$@ && \ 51 | export sample_project=$${rel#release/} && \ 52 | export tag="$$(git describe --always --dirty)" && \ 53 | export pkgname="$${sample_project}-sample-project-$${tag}" && \ 54 | export pkgdir="release/$${pkgname}" && \ 55 | rm -rf "$${pkgdir}" && mkdir -p "$${pkgdir}" && \ 56 | sample-projects/$${sample_project}/prepare_release.sh "$${pkgdir}" && \ 57 | cd release && zip -r "$${pkgname}.zip" "$${pkgname}" && cd - && \ 58 | ln -sfn $${pkgname} release/$${sample_project} 59 | 60 | release: clean $(release_drivers) $(release_sample_projects) 61 | 62 | utils: 63 | $(MAKE) -C utils 64 | 65 | clean_utils: 66 | $(MAKE) -C utils clean 67 | 68 | $(clean_drivers): 69 | export rel=$@ && \ 70 | export driver=$${rel#clean_} && \ 71 | cd $${driver} && $(MAKE) clean $(MFLAGS) && cd - 72 | 73 | clean: $(clean_drivers) clean_utils 74 | rm -rf release 75 | $(RM) sht-common/sht_git_version.c 76 | 77 | style-fix: 78 | @if [ $$(git status --porcelain -uno 2> /dev/null | wc -l) -gt "0" ]; \ 79 | then \ 80 | echo "Refusing to run on dirty git state. Commit your changes first."; \ 81 | exit 1; \ 82 | fi; \ 83 | git ls-files | grep -e '\.\(c\|h\|cpp\)$$' | xargs clang-format -i -style=file; 84 | 85 | style-check: style-fix 86 | @if [ $$(git status --porcelain -uno 2> /dev/null | wc -l) -gt "0" ]; \ 87 | then \ 88 | echo "Style check failed:"; \ 89 | git diff; \ 90 | git checkout -f; \ 91 | exit 1; \ 92 | fi; 93 | -------------------------------------------------------------------------------- /utils/sensirion_temperature_unit_conversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef SENSIRION_TEMPERATURE_UNIT_CONVERSION_H 33 | #define SENSIRION_TEMPERATURE_UNIT_CONVERSION_H 34 | #include "sensirion_arch_config.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** 41 | * sensirion_celsius_to_fahrenheit() - Convert temperature in degree Celsius 42 | * (Centigrade) to degree Fahrenheit 43 | * 44 | * Note that inputs not in the range -291degC <= degC <= 291 will result in 45 | * invalid results. 46 | * 47 | * @param temperature_milli_celsius The temperature measurement in milli 48 | * degree Celsius, i.e. degree Celsius 49 | * multiplied by 1000. 50 | * 51 | * @return The temperature measurement in milli 52 | * degree Fahrenheit, i.e. degree 53 | * Fahrenheit multiplied by 1000. 54 | */ 55 | int32_t sensirion_celsius_to_fahrenheit(int32_t temperature_milli_celsius); 56 | 57 | /** 58 | * sensirion_fahrenheit_to_celsius() - Convert temperature in degree Fahrenheit 59 | * to degree Celsius (Centigrade) 60 | * 61 | * Note that inputs not in the range -3571degF <= degF <= 3635degF will result 62 | * in invalid results. 63 | * 64 | * @param temperature_milli_fahrenheit The temperature measurement in milli 65 | * degree Fahrenheit, i.e. degree 66 | * Fahrenheit multiplied by 1000. 67 | * 68 | * @return The temperature measurement in milli 69 | * degree Celsius, i.e. degree Celsius 70 | * multiplied by 1000. 71 | */ 72 | int32_t sensirion_fahrenheit_to_celsius(int32_t temperature_milli_fahrenheit); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* SENSIRION_TEMPERATURE_UNIT_CONVERSION_H */ 79 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/Source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include "shtc1.h" 33 | #include "system.h" 34 | #include 35 | 36 | static void led_init(void); 37 | static void led_blue(bool on); 38 | static void led_green(bool on); 39 | 40 | int main(void) { 41 | /* Initialize the i2c bus for the current platform */ 42 | sensirion_i2c_init(); 43 | 44 | led_init(); 45 | 46 | /* Busy loop for initialization, because the main loop does not work without 47 | * a sensor. 48 | */ 49 | while (shtc1_probe() != STATUS_OK) { 50 | /* Blink LED as long as probing fails */ 51 | led_green(true); 52 | sensirion_sleep_usec(100000); 53 | led_green(false); 54 | sensirion_sleep_usec(100000); 55 | } 56 | 57 | /* probe sucessfull -> green LED on */ 58 | led_green(true); 59 | 60 | while (1) { 61 | int32_t temperature, humidity; 62 | /* Measure temperature and relative humidity and store into variables 63 | * temperature, humidity (each output multiplied by 1000). 64 | */ 65 | int8_t ret = shtc1_measure_blocking_read(&temperature, &humidity); 66 | if (ret == STATUS_OK) { 67 | led_green(true); 68 | /* if the Relative Humidity is over 50% light up the blue LED */ 69 | led_blue(humidity > 50000); 70 | } else { 71 | /* error -> green LED off */ 72 | led_green(false); 73 | } 74 | /* wait 1 second */ 75 | sensirion_sleep_usec(1000000); 76 | } 77 | } 78 | 79 | /* -- adapt this code for your platform -- */ 80 | static void led_init(void) { 81 | RCC->APB2ENR |= 0x00000010; /* I/O port C clock enabled */ 82 | GPIOC->CRH &= 0xFFFFFF00; /* set general purpose output mode for LEDs */ 83 | GPIOC->CRH |= 0x00000011; 84 | GPIOC->BSRR = 0x03000000; /* LEDs off */ 85 | } 86 | 87 | /* -- adapt this code for your platform -- */ 88 | static void led_blue(bool on) { 89 | if (on) { 90 | GPIOC->BSRR = 0x00000100; 91 | } else { 92 | GPIOC->BSRR = 0x01000000; 93 | } 94 | } 95 | 96 | /* -- adapt this code for your platform -- */ 97 | static void led_green(bool on) { 98 | if (on) { 99 | GPIOC->BSRR = 0x00000200; 100 | } else { 101 | GPIOC->BSRR = 0x02000000; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tests/shtc1-test.cpp: -------------------------------------------------------------------------------- 1 | #include "sensirion_common.h" 2 | #include "sensirion_test_setup.h" 3 | #include "shtc1.h" 4 | 5 | static void shtc1_run_test() { 6 | int16_t ret; 7 | int32_t temperature; 8 | int32_t humidity; 9 | uint32_t serial; 10 | 11 | ret = shtc1_measure_blocking_read(&temperature, &humidity); 12 | CHECK_ZERO_TEXT(ret, "shtc1_measure_blocking_read"); 13 | CHECK_TRUE_TEXT(temperature >= 5000 && temperature <= 45000, 14 | "shtc1_measure_blocking_read temperature"); 15 | CHECK_TRUE_TEXT(humidity >= 0 && humidity <= 100000, 16 | "shtc1_measure_blocking_read humidity"); 17 | 18 | ret = shtc1_measure(); 19 | CHECK_ZERO_TEXT(ret, "shtc1_measure"); 20 | 21 | sensirion_sleep_usec(SHTC1_MEASUREMENT_DURATION_USEC); 22 | 23 | ret = shtc1_read(&temperature, &humidity); 24 | CHECK_ZERO_TEXT(ret, "shtc1_read"); 25 | CHECK_TRUE_TEXT(temperature >= 5000 && temperature <= 45000, 26 | "shtc1_read temperature"); 27 | CHECK_TRUE_TEXT(humidity >= 0 && humidity <= 100000, "shtc1_read humidity"); 28 | 29 | ret = shtc1_read_serial(&serial); 30 | CHECK_ZERO_TEXT(ret, "shtc1_read_serial"); 31 | printf("SHTC1 serial: %u\n", serial); 32 | 33 | const char* version = shtc1_get_driver_version(); 34 | printf("shtc1_get_driver_version: %s\n", version); 35 | 36 | uint8_t addr = shtc1_get_configured_address(); 37 | CHECK_EQUAL_TEXT(0x70, addr, "shtc1_get_configured_address"); 38 | } 39 | 40 | static void shtc1_test_all_power_modes() { 41 | int16_t ret; 42 | 43 | printf("Running tests in normal mode...\n"); 44 | ret = shtc1_probe(); 45 | CHECK_ZERO_TEXT(ret, "shtc1_probe before normal mode"); 46 | shtc1_run_test(); 47 | 48 | printf("Running tests in low power mode...\n"); 49 | ret = shtc1_probe(); 50 | CHECK_ZERO_TEXT(ret, "shtc1_probe before low power mode"); 51 | shtc1_enable_low_power_mode(1); 52 | shtc1_run_test(); 53 | } 54 | 55 | static int16_t shtc1_test_sleep() { 56 | int16_t ret = shtc1_probe(); 57 | CHECK_ZERO_TEXT(ret, "shtc1_probe before disabling sleep"); 58 | ret = shtc1_sleep(); 59 | return ret; 60 | } 61 | 62 | static void shtc1_sleep_success() { 63 | int16_t ret = shtc1_test_sleep(); 64 | CHECK_ZERO_TEXT(ret, "shtc1_sleep should succeed, but it didn't"); 65 | ret = shtc1_wake_up(); 66 | CHECK_ZERO_TEXT(ret, "shtc1_wakeup should succeed, but it didn't"); 67 | } 68 | 69 | static void shtc1_sleep_fail() { 70 | int16_t ret = shtc1_test_sleep(); 71 | CHECK_TRUE_TEXT(ret, "shtc1_sleep should fail, but didn't"); 72 | ret = shtc1_wake_up(); 73 | CHECK_TRUE_TEXT(ret, "shtc1_wake_up should fail, but didn't"); 74 | } 75 | 76 | static void test_teardown() { 77 | int16_t ret = sensirion_i2c_general_call_reset(); 78 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_general_call_reset"); 79 | sensirion_i2c_release(); 80 | } 81 | 82 | TEST_GROUP (SHTC1_Tests) { 83 | void setup() { 84 | sensirion_i2c_init(); 85 | int16_t ret = sensirion_i2c_mux_set_single_channel(0x71, 6); 86 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_mux_select_TEXT(0x71, 6)"); 87 | } 88 | 89 | void teardown() { 90 | test_teardown(); 91 | } 92 | }; 93 | 94 | TEST_GROUP (SHTC3_Tests) { 95 | void setup() { 96 | sensirion_i2c_init(); 97 | int16_t ret = sensirion_i2c_mux_set_single_channel(0x72, 0); 98 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_mux_select_TEXT(0x72, 0)"); 99 | } 100 | 101 | void teardown() { 102 | test_teardown(); 103 | } 104 | }; 105 | 106 | TEST_GROUP (SHTW2_Tests) { 107 | void setup() { 108 | sensirion_i2c_init(); 109 | int16_t ret = sensirion_i2c_mux_set_single_channel(0x71, 0); 110 | CHECK_ZERO_TEXT(ret, "sensirion_i2c_mux_select_TEXT(0x71, 0)"); 111 | } 112 | 113 | void teardown() { 114 | test_teardown(); 115 | } 116 | }; 117 | 118 | TEST (SHTC1_Tests, SHTC1Test) { shtc1_test_all_power_modes(); } 119 | 120 | TEST (SHTC1_Tests, SHTC1Test_sleep) { 121 | shtc1_sleep_fail(); 122 | shtc1_test_all_power_modes(); 123 | } 124 | 125 | TEST (SHTC3_Tests, SHTC3Test) { shtc1_test_all_power_modes(); } 126 | 127 | TEST (SHTC3_Tests, SHTC3Test_sleep) { 128 | shtc1_sleep_success(); 129 | shtc1_test_all_power_modes(); 130 | } 131 | 132 | TEST (SHTW2_Tests, SHTW2Test) { shtc1_test_all_power_modes(); } 133 | 134 | TEST (SHTW2_Tests, SHTW2Test_sleep) { 135 | shtc1_sleep_fail(); 136 | shtc1_test_all_power_modes(); 137 | } 138 | -------------------------------------------------------------------------------- /utils/sensirion_humidity_conversion.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include "sensirion_humidity_conversion.h" 33 | 34 | #ifndef ARRAY_SIZE 35 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) 36 | #endif /* ARRAY_SIZE */ 37 | 38 | /* T_LO and T_HI parametrize the first and last temperature step of the absolute 39 | * humidity lookup table (at 100%RH). The lookup table entries have to be 40 | * linearly spaced. We provide a python script to generate look up tables based 41 | * on customizable T_LO/T_HI and number of steps. */ 42 | 43 | /** 44 | * T_LO - Towest temperature sampling point in the lookup table. 45 | * Temperature value in milli-degrees Centigrade 46 | */ 47 | #define T_LO (-20000) 48 | 49 | /** 50 | * T_HI - Towest temperature sampling point in the lookup table. 51 | * Temperature value in milli-degrees Celsius (Centigrade) 52 | */ 53 | #define T_HI (70000) 54 | 55 | /** 56 | * Lookup table for linearly spaced temperature points between T_LO and T_HI 57 | * Absolute Humidity value in mg/m^3. 58 | */ 59 | static const uint32_t AH_LUT_100RH[] = {1078, 2364, 4849, 9383, 17243, 60 | 30264, 50983, 82785, 130048, 198277}; 61 | /** 62 | * T_STEP is the temperature step between the sampling points in the lookup 63 | * table. It is determined by T_HI, T_LO and the number of entries in 64 | * AH_LUT_100RH and does not have to be adapted when changing the paramters. 65 | */ 66 | static const uint32_t T_STEP = (T_HI - T_LO) / (ARRAY_SIZE(AH_LUT_100RH) - 1); 67 | 68 | uint32_t sensirion_calc_absolute_humidity(int32_t temperature_milli_celsius, 69 | int32_t humidity_milli_percent) { 70 | uint32_t t, i, rem, ret; 71 | 72 | if (humidity_milli_percent <= 0) 73 | return 0; 74 | 75 | if (temperature_milli_celsius < T_LO) 76 | t = 0; 77 | else 78 | t = (uint32_t)(temperature_milli_celsius - T_LO); 79 | 80 | i = t / T_STEP; 81 | rem = t % T_STEP; 82 | 83 | if (i >= ARRAY_SIZE(AH_LUT_100RH) - 1) { 84 | ret = AH_LUT_100RH[ARRAY_SIZE(AH_LUT_100RH) - 1]; 85 | 86 | } else if (rem == 0) { 87 | ret = AH_LUT_100RH[i]; 88 | 89 | } else { 90 | ret = (AH_LUT_100RH[i] + 91 | ((AH_LUT_100RH[i + 1] - AH_LUT_100RH[i]) * rem / T_STEP)); 92 | } 93 | 94 | // Code is mathematically (but not numerically) equivalent to 95 | // return (ret * (humidity_milli_percent)) / 100000; 96 | // Maximum ret = 198277 (Or last entry from AH_LUT_100RH) 97 | // Maximum humidity_milli_percent = 119000 (theoretical maximum) 98 | // Multiplication might overflow with a maximum of 3 digits 99 | // Trick: ((ret >> 3) * (uint32_t)humidity_milli_percent) never overflows 100 | // Now we only need to divide by 12500, as the tripple righ shift 101 | // divides by 8 102 | 103 | return ((ret >> 3) * (uint32_t)(humidity_milli_percent)) / 12500; 104 | } 105 | -------------------------------------------------------------------------------- /sht4x/sht4x.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * \file 34 | * 35 | * \brief Sensirion SHT4X driver implementation 36 | * 37 | * This module provides access to the SHT4X functionality over a generic I2C 38 | * interface. It supports measurements without clock stretching only. 39 | */ 40 | 41 | #include "sht4x.h" 42 | #include "sensirion_arch_config.h" 43 | #include "sensirion_common.h" 44 | #include "sensirion_i2c.h" 45 | 46 | /* all measurement commands return T (CRC) RH (CRC) */ 47 | #define SHT4X_CMD_MEASURE_HPM 0xFD 48 | #define SHT4X_CMD_MEASURE_LPM 0xE0 49 | #define SHT4X_CMD_READ_SERIAL 0x89 50 | #define SHT4X_CMD_DURATION_USEC 1000 51 | 52 | #define SHT4X_ADDRESS 0x44 53 | 54 | static uint8_t sht4x_cmd_measure = SHT4X_CMD_MEASURE_HPM; 55 | static uint16_t sht4x_cmd_measure_delay_us = SHT4X_MEASUREMENT_DURATION_USEC; 56 | 57 | int16_t sht4x_measure_blocking_read(int32_t* temperature, int32_t* humidity) { 58 | int16_t ret; 59 | 60 | ret = sht4x_measure(); 61 | if (ret) 62 | return ret; 63 | sensirion_sleep_usec(sht4x_cmd_measure_delay_us); 64 | return sht4x_read(temperature, humidity); 65 | } 66 | 67 | int16_t sht4x_measure(void) { 68 | return sensirion_i2c_write(SHT4X_ADDRESS, &sht4x_cmd_measure, 1); 69 | } 70 | 71 | int16_t sht4x_read(int32_t* temperature, int32_t* humidity) { 72 | uint16_t words[2]; 73 | int16_t ret = sensirion_i2c_read_words(SHT4X_ADDRESS, words, 74 | SENSIRION_NUM_WORDS(words)); 75 | /** 76 | * formulas for conversion of the sensor signals, optimized for fixed point 77 | * algebra: 78 | * Temperature = 175 * S_T / 65535 - 45 79 | * Relative Humidity = 125 * (S_RH / 65535) - 6 80 | */ 81 | *temperature = ((21875 * (int32_t)words[0]) >> 13) - 45000; 82 | *humidity = ((15625 * (int32_t)words[1]) >> 13) - 6000; 83 | 84 | return ret; 85 | } 86 | 87 | int16_t sht4x_probe(void) { 88 | uint32_t serial; 89 | 90 | return sht4x_read_serial(&serial); 91 | } 92 | 93 | void sht4x_enable_low_power_mode(uint8_t enable_low_power_mode) { 94 | if (enable_low_power_mode) { 95 | sht4x_cmd_measure = SHT4X_CMD_MEASURE_LPM; 96 | sht4x_cmd_measure_delay_us = SHT4X_MEASUREMENT_DURATION_LPM_USEC; 97 | } else { 98 | sht4x_cmd_measure = SHT4X_CMD_MEASURE_HPM; 99 | sht4x_cmd_measure_delay_us = SHT4X_MEASUREMENT_DURATION_USEC; 100 | } 101 | } 102 | 103 | int16_t sht4x_read_serial(uint32_t* serial) { 104 | const uint8_t cmd = SHT4X_CMD_READ_SERIAL; 105 | int16_t ret; 106 | uint16_t serial_words[SENSIRION_NUM_WORDS(*serial)]; 107 | 108 | ret = sensirion_i2c_write(SHT4X_ADDRESS, &cmd, 1); 109 | if (ret) 110 | return ret; 111 | 112 | sensirion_sleep_usec(SHT4X_CMD_DURATION_USEC); 113 | ret = sensirion_i2c_read_words(SHT4X_ADDRESS, serial_words, 114 | SENSIRION_NUM_WORDS(serial_words)); 115 | *serial = ((uint32_t)serial_words[0] << 16) | serial_words[1]; 116 | 117 | return ret; 118 | } 119 | 120 | const char* sht4x_get_driver_version(void) { 121 | return SHT_DRV_VERSION_STR; 122 | } 123 | 124 | uint8_t sht4x_get_configured_address(void) { 125 | return SHT4X_ADDRESS; 126 | } 127 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), 4 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 5 | 6 | ## [Unreleased] 7 | 8 | 9 | ## [5.3.0] - 2021-03-16 10 | 11 | * [`added`] SHT3x driver added macros to easily parse the STATUS register relevant bits 12 | * [`added`] SHT3x driver support for alert thresholds configuration (read and write commands) 13 | * [`added`] SHT3x driver support for clear status register 14 | * [`added`] SHT3x driver allows use of 2 sensors in parallel (addresses 0x44 & 0x45) 15 | 16 | ## [5.2.1] - 2020-12-14 17 | 18 | * [`changed`] Makefile to only include needed files from embedded-common 19 | * [`changed`] Updated embedded-common to 0.1.0 to improve compatibility when 20 | using multiple embedded drivers 21 | 22 | ## [5.2.0] - 2020-09-10 23 | 24 | * [`added`] SHT4x Support 25 | 26 | ## [5.1.0] - 2020-06-12 27 | 28 | * [`changed`] Cleanup and better document stm32 sample code 29 | * [`changed`] Use configuration independent endianness conversions. No more 30 | need to correctly set `SENSIRION_BIG_ENDIAN` 31 | 32 | ## [5.0.0] - 2020-04-29 33 | 34 | * [`changed`] Replace SHTC3's auto-sleeping with manual sleeping for better 35 | control of the sensor and easier-to-read code. 36 | - Adds the functions `shtc1_sleep()` and `shtc1_wake_up()` 37 | Despite the name, the functions only work on the SHTC3. 38 | - Remove `shtc1_disable_sleeping()`. 39 | * [`removed`] Remove the `AUTHORS` file from the driver and the 40 | `embedded-common` submodule, as it adds more noise than benefit. 41 | The contributors can be found in the git log. 42 | * [`fixed`] Copy correct `CHANGELOG.md` and `LICENSE` files to target 43 | locations when running the `release` target of the driver's root 44 | Makefile. 45 | * [`fixed`] Fix uVision compilation warnings (#1295-D: Deprecated 46 | declaration of shtc1_sleep - give arg types) 47 | * [`added`] Add convenience function convert relative to absolute humidity 48 | * [`added`] Add convenience functions convert between Celsius and Fahrenheit 49 | 50 | ## [4.1.0] - 2019-09-13 51 | 52 | * [`fixed`] Fix warnings about sign conversion 53 | * [`fixed`] Improved compatibility with C++ compilers 54 | * [`added`] Add functions to read out the serial id: 55 | - `sht3x_read_serial_id(int32_t *serial_id)` 56 | - `shtc1_read_serial_id(int32_t *serial_id)` 57 | * [`changed`] Split out `default_config.inc` from Makefile to configure paths 58 | and CFLAGS for both SHTC1 and SHT3X drivers 59 | * [`changed`] Only one example with either `hw_i2c` or `sw_i2c` is built, 60 | depending on `CONFIG_I2C_TYPE`. Defaults to `hw_i2c`. 61 | * [`changed`] Move the defined constants `SHT3X_MEASUREMENT_DURATION_USEC` 62 | and `SHTC1_MEASUREMENT_DURATION_USEC` to their respective 63 | header files. 64 | 65 | ## [4.0.0] - 2019-07-01 66 | 67 | * [`changed`] Return types are now `int16_t` instead of `int8_t` (in line with 68 | other embedded drivers). 69 | * [`changed`] Functions are now dedicated per sensor (e.g. `sht3x_probe()` 70 | instead of `sht_probe()`) 71 | * [`added`] New return values for wakeup/sleep failed 72 | (`STATUS_WAKEUP_FAILED`, `STATUS_SLEEP_FAILED`) 73 | * [`fixed`] Fix SHTC3 issues when calling `probe()` multiple times 74 | * [`changed`] Move the i2c init call out of `probe()` and into the example 75 | * [`changed`] Rename `git_version.[ch]` to `sht_git_version.[ch]` 76 | 77 | ## [3.0.0] - 2019-05-14 78 | 79 | * [`changed`] Use stdint types, e.g. `uint16_t` instead of `u16` 80 | 81 | ## [2.1.0] - 2018-06-27 82 | 83 | * [`added`] Support for SHTC3's sleep mode (included in shtc1 package) 84 | * [`added`] Support low power mode on SHTC1 (and family) 85 | 86 | ## [2.0.0] - 2018-05-14 87 | 88 | * First public release 89 | 90 | [Unreleased]: https://github.com/Sensirion/embedded-sht/compare/5.3.0...master 91 | [5.3.0]: https://github.com/Sensirion/embedded-sht/compare/5.2.1...5.3.0 92 | [5.2.1]: https://github.com/Sensirion/embedded-sht/compare/5.2.0...5.2.1 93 | [5.2.0]: https://github.com/Sensirion/embedded-sht/compare/5.1.0...5.2.0 94 | [5.1.0]: https://github.com/Sensirion/embedded-sht/compare/5.0.0...5.1.0 95 | [5.0.0]: https://github.com/Sensirion/embedded-sht/compare/4.1.0...5.0.0 96 | [4.1.0]: https://github.com/Sensirion/embedded-sht/compare/4.0.0...4.1.0 97 | [4.0.0]: https://github.com/Sensirion/embedded-sht/compare/3.0.0...4.0.0 98 | [3.0.0]: https://github.com/Sensirion/embedded-sht/compare/2.1.0...3.0.0 99 | [2.1.0]: https://github.com/Sensirion/embedded-sht/compare/2.0.0...2.1.0 100 | [2.0.0]: https://github.com/Sensirion/embedded-sht/releases/tag/2.0.0 101 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/Source/sensirion_sw_i2c_implementation.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include "sw_i2c/sensirion_sw_i2c_gpio.h" 33 | #include "system.h" 34 | 35 | //-- Defines for IO-Pins ------------------------------------------------------- 36 | // I2C IO-Pins /* -- adapt the defines for your uC -- */ 37 | 38 | // SDA on port B, bit 9 39 | #define SDA_LOW() (GPIOB->BSRR = 0x02000000) // set SDA to low 40 | #define SDA_OPEN() (GPIOB->BSRR = 0x00000200) // set SDA to open-drain 41 | #define SDA_READ() (GPIOB->IDR & 0x0200) // read SDA 42 | 43 | // SCL on port B, bit 8 /* -- adapt the defines for your uC -- */ 44 | #define SCL_LOW() (GPIOB->BSRR = 0x01000000) // set SCL to low 45 | #define SCL_OPEN() (GPIOB->BSRR = 0x00000100) // set SCL to open-drain 46 | #define SCL_READ() (GPIOB->IDR & 0x0100) // read SCL 47 | 48 | /** 49 | * Initialize all hard- and software components that are needed to set the 50 | * SDA and SCL pins. 51 | */ 52 | void sensirion_init_pins(void) { 53 | RCC->APB2ENR |= 0x00000008; // I/O port B clock enabled 54 | 55 | SDA_OPEN(); // I2C-bus idle mode SDA released 56 | SCL_OPEN(); // I2C-bus idle mode SCL released 57 | 58 | // SDA on port B, bit 9 59 | // SCL on port B, bit 8 60 | GPIOB->CRH &= 0xFFFFFF00; // set open-drain output for SDA and SCL 61 | GPIOB->CRH |= 0x00000055; // 62 | } 63 | 64 | void sensirion_release_pins(void) { 65 | // do nothing 66 | } 67 | 68 | /** 69 | * Configure the SDA pin as an input. With an external pull-up resistor the line 70 | * should be left floating, without external pull-up resistor, the input must be 71 | * configured to use the internal pull-up resistor. 72 | */ 73 | void sensirion_SDA_in() { 74 | SDA_OPEN(); 75 | } 76 | 77 | /** 78 | * Configure the SDA pin as an output and drive it low or set to logical false. 79 | */ 80 | void sensirion_SDA_out() { 81 | SDA_LOW(); 82 | } 83 | 84 | /** 85 | * Read the value of the SDA pin. 86 | * @returns 0 if the pin is low and 1 otherwise. 87 | */ 88 | uint8_t sensirion_SDA_read() { 89 | return SDA_READ() ? 1 : 0; 90 | } 91 | 92 | /** 93 | * Configure the SCL pin as an input. With an external pull-up resistor the line 94 | * should be left floating, without external pull-up resistor, the input must be 95 | * configured to use the internal pull-up resistor. 96 | */ 97 | void sensirion_SCL_in() { 98 | SCL_OPEN(); 99 | } 100 | 101 | /** 102 | * Configure the SCL pin as an output and drive it low or set to logical false. 103 | */ 104 | void sensirion_SCL_out() { 105 | SCL_LOW(); 106 | } 107 | 108 | /** 109 | * Read the value of the SCL pin. 110 | * @returns 0 if the pin is low and 1 otherwise. 111 | */ 112 | uint8_t sensirion_SCL_read() { 113 | return SCL_READ() ? 1 : 0; 114 | } 115 | 116 | /** 117 | * Sleep for a given number of microseconds. The function should delay the 118 | * execution approximately, but no less than, the given time. 119 | * 120 | * The precision needed depends on the desired i2c frequency, i.e. should be 121 | * exact to about half a clock cycle (defined in 122 | * `SENSIRION_I2C_CLOCK_PERIOD_USEC` in `sensirion_arch_config.h`). 123 | * 124 | * Example with 400kHz requires a precision of 1 / (2 * 400kHz) == 1.25usec. 125 | * 126 | * @param useconds the sleep time in microseconds 127 | */ 128 | void sensirion_sleep_usec(uint32_t useconds) { 129 | for (uint32_t i = 0; i < useconds; i++) { 130 | __nop(); // nop's may be added or removed for timing adjustment 131 | __nop(); 132 | __nop(); 133 | __nop(); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /sht4x/sht4x.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * \file 34 | * 35 | * \brief Sensirion SHT driver interface 36 | * 37 | * This module provides access to the SHT functionality over a generic I2C 38 | * interface. It supports measurements without clock stretching only. 39 | */ 40 | 41 | #ifndef SHT4X_H 42 | #define SHT4X_H 43 | 44 | #include "sensirion_arch_config.h" 45 | #include "sensirion_i2c.h" 46 | #include "sht_git_version.h" 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | #define STATUS_OK 0 53 | #define STATUS_ERR_BAD_DATA (-1) 54 | #define STATUS_CRC_FAIL (-2) 55 | #define STATUS_UNKNOWN_DEVICE (-3) 56 | #define SHT4X_MEASUREMENT_DURATION_USEC 10000 /* 10ms "high repeatability" */ 57 | #define SHT4X_MEASUREMENT_DURATION_LPM_USEC \ 58 | 2500 /* 2.5ms "low repeatability" \ 59 | */ 60 | 61 | /** 62 | * Detects if a sensor is connected by reading out the ID register. 63 | * If the sensor does not answer or if the answer is not the expected value, 64 | * the test fails. 65 | * 66 | * @return 0 if a sensor was detected 67 | */ 68 | int16_t sht4x_probe(void); 69 | 70 | /** 71 | * Starts a measurement and then reads out the results. This function blocks 72 | * while the measurement is in progress. The duration of the measurement depends 73 | * on the sensor in use, please consult the datasheet. 74 | * Temperature is returned in [degree Celsius], multiplied by 1000, 75 | * and relative humidity in [percent relative humidity], multiplied by 1000. 76 | * 77 | * @param temperature the address for the result of the temperature 78 | * measurement 79 | * @param humidity the address for the result of the relative humidity 80 | * measurement 81 | * @return 0 if the command was successful, else an error code. 82 | */ 83 | int16_t sht4x_measure_blocking_read(int32_t* temperature, int32_t* humidity); 84 | 85 | /** 86 | * Starts a measurement in high precision mode. Use sht4x_read() to read out the 87 | * values, once the measurement is done. The duration of the measurement depends 88 | * on the sensor in use, please consult the datasheet. 89 | * 90 | * @return 0 if the command was successful, else an error code. 91 | */ 92 | int16_t sht4x_measure(void); 93 | 94 | /** 95 | * Reads out the results of a measurement that was previously started by 96 | * sht4x_measure(). If the measurement is still in progress, this function 97 | * returns an error. 98 | * Temperature is returned in [degree Celsius], multiplied by 1000, 99 | * and relative humidity in [percent relative humidity], multiplied by 1000. 100 | * 101 | * @param temperature the address for the result of the temperature 102 | * measurement 103 | * @param humidity the address for the result of the relative humidity 104 | * measurement 105 | * @return 0 if the command was successful, else an error code. 106 | */ 107 | int16_t sht4x_read(int32_t* temperature, int32_t* humidity); 108 | 109 | /** 110 | * Enable or disable the SHT's low power mode 111 | * 112 | * @param enable_low_power_mode 1 to enable low power mode, 0 to disable 113 | */ 114 | void sht4x_enable_low_power_mode(uint8_t enable_low_power_mode); 115 | 116 | /** 117 | * Read out the serial number 118 | * 119 | * @param serial the address for the result of the serial number 120 | * @return 0 if the command was successful, else an error code. 121 | */ 122 | int16_t sht4x_read_serial(uint32_t* serial); 123 | 124 | /** 125 | * Return the driver version 126 | * 127 | * @return Driver version string 128 | */ 129 | const char* sht4x_get_driver_version(void); 130 | 131 | /** 132 | * Returns the configured SHT4x address. 133 | * 134 | * @return SHT4x_ADDRESS 135 | */ 136 | uint8_t sht4x_get_configured_address(void); 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | #endif /* SHT4X_H */ 143 | -------------------------------------------------------------------------------- /utils/ah_lut.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | """ 4 | (c) Copyright 2018 Sensirion AG, Switzerland 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of Sensirion AG nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | """ 33 | 34 | import math 35 | 36 | 37 | # Generate a look-up table for the interpolation of the relative humidity to 38 | # absolute humidity conversion within a specifig temperature region (e.g. -20°C 39 | # to 70°C in steps of 10°C) 40 | # As part of the output, the mean error over each discrete (t, rh) point within 41 | # a region of interest is printed (See `quantify_ah_lut_error`) 42 | 43 | def calc_ah(t, rh): 44 | """ Mathematically correct AH computation """ 45 | return 216.7 * ( 46 | (rh / 100. * 6.112 * math.exp(17.62 * t / (243.12 + t))) / 47 | (273.15 + t)) 48 | 49 | 50 | def gen_ah_lut(t_range): 51 | """ Generate the AH Look Up Table at 100%RH (0..100 scales linearly) """ 52 | return [calc_ah(t, 100) for t in t_range] 53 | 54 | 55 | def ah_lookup(ah_lut, t_lo, t_hi, temp, rh): 56 | if rh == 0: 57 | return 0 58 | 59 | t_step = (t_hi - t_lo) / (len(ah_lut) - 1) 60 | t = temp - t_lo 61 | i = int(t / t_step) 62 | rem = t % t_step 63 | 64 | if i >= len(ah_lut) - 1: 65 | return ah_lut[-1] * (rh / 100.) 66 | 67 | if rem == 0: 68 | return ah_lut[i] * (rh / 100.) 69 | return (ah_lut[i] + (ah_lut[i + 1] - ah_lut[i]) * rem / t_step) * rh / 100. 70 | 71 | 72 | def c_ah_lookup(ah_lut, t_lo, t_hi, temp, rh): 73 | """ Fixed point implementation (for C conversion) 74 | The only non-fixed point aspect is the final division by 1000. for 75 | comparison with the floating point version """ 76 | if rh == 0: 77 | return 0 78 | 79 | rh = int(rh * 1000) 80 | norm_humi = (rh * 82) >> 13 81 | temp = int(temp * 1000) 82 | t_lo = int(t_lo * 1000) 83 | t_hi = int(t_hi * 1000) 84 | 85 | t_step = int((t_hi - t_lo) / (len(ah_lut) - 1)) 86 | t = temp - t_lo 87 | i = int(t / t_step) 88 | rem = t % t_step 89 | 90 | if i >= len(ah_lut) - 1: 91 | return (ah_lut[-1] * norm_humi) / 1000. 92 | if rem == 0: 93 | return (ah_lut[i] * norm_humi) / 1000. 94 | 95 | return ((ah_lut[i] + (ah_lut[i + 1] - ah_lut[i]) * rem / t_step) * norm_humi) / 1000. 96 | 97 | 98 | def quantify_ah_lut_error(ah_lut, t_lo, t_hi, t_range, rh_range): 99 | s_float = 0 100 | s_int = 0 101 | for t in t_range: 102 | for rh in rh_range: 103 | s_float += abs(calc_ah(t, rh) - ah_lookup(ah_lut, t_lo, t_hi, t, rh)) 104 | s_int += abs(calc_ah(t, rh) - c_ah_lookup(ah_lut, t_lo, t_hi, t, rh)) 105 | div = (len(t_range) * len(rh_range)) 106 | return (s_float / div, s_int / div) 107 | 108 | 109 | if __name__ == '__main__': 110 | T_LO = -20 111 | T_HI = 70 112 | T_STEP = 10 113 | lut = gen_ah_lut(range(T_LO, T_HI+1, T_STEP)) 114 | print("The average absolute error over the range in 1°C steps is:") 115 | print("error avg(abs(ah(t,rh) - lookup(t,rh))) for T: -20..45, RH: 20..80 (float, int)") 116 | print(quantify_ah_lut_error(lut, T_LO, T_HI, range(T_LO, 45, 1), range(20, 80, 1))) 117 | 118 | # print("Comparison of the absolute humdity to the lookup-table value over a 119 | # "selected set of (T, %RH) pairs") 120 | # for t, rh in [(-20, 0), (-20, 100), (-19.9, 100), (-15.1, 90), (-15, 90), 121 | # (-14.9, 90), (20, 50), (20, 100), (22.5, 50), (55, 70), (65, 70), (75, 70), (140, 50)]: 122 | # print("AH({}, {}) = {} ~ {} ~ {}".format(t, rh, calc_ah(t, rh), 123 | # ah_lookup(lut, T_LO, T_HI, t, rh), 124 | # c_ah_lookup(lut, T_LO, T_HI, t, rh))) 125 | 126 | print("") 127 | print("C Source:") 128 | print(""" 129 | #define T_LO ({t_low}) 130 | #define T_HI ({t_high}) 131 | static const uint32_t AH_LUT_100RH[] = {{{ah_lut_100rh}}};""" 132 | .format(t_low=T_LO, t_high=T_HI, 133 | ah_lut_100rh=', '.join(['{:.0f}'.format(ah * 1000) 134 | for ah in lut]))) 135 | -------------------------------------------------------------------------------- /shtc1/shtc1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * \file 34 | * 35 | * \brief Sensirion SHTC1 (and compatible) driver implementation 36 | * 37 | * This module provides access to the SHTC1 functionality over a generic I2C 38 | * interface. It supports measurements without clock stretching only. 39 | * 40 | * SHTC1 compatible sensors: SHTW1, SHTW2, SHTC3 41 | */ 42 | 43 | #include "shtc1.h" 44 | #include "sensirion_arch_config.h" 45 | #include "sensirion_common.h" 46 | #include "sensirion_i2c.h" 47 | 48 | /* all measurement commands return T (CRC) RH (CRC) */ 49 | #if USE_SENSIRION_CLOCK_STRETCHING 50 | #define SHTC1_CMD_MEASURE_HPM 0x7CA2 51 | #define SHTC1_CMD_MEASURE_LPM 0x6458 52 | #else /* USE_SENSIRION_CLOCK_STRETCHING */ 53 | #define SHTC1_CMD_MEASURE_HPM 0x7866 54 | #define SHTC1_CMD_MEASURE_LPM 0x609C 55 | #endif /* USE_SENSIRION_CLOCK_STRETCHING */ 56 | static const uint16_t SHTC1_CMD_DURATION_USEC = 1000; 57 | 58 | static const uint16_t SHTC3_CMD_SLEEP = 0xB098; 59 | static const uint16_t SHTC3_CMD_WAKEUP = 0x3517; 60 | #ifdef SHT_ADDRESS 61 | static const uint8_t SHTC1_ADDRESS = SHT_ADDRESS; 62 | #else 63 | static const uint8_t SHTC1_ADDRESS = 0x70; 64 | #endif 65 | 66 | static uint16_t shtc1_cmd_measure = SHTC1_CMD_MEASURE_HPM; 67 | 68 | int16_t shtc1_sleep(void) { 69 | return sensirion_i2c_write_cmd(SHTC1_ADDRESS, SHTC3_CMD_SLEEP); 70 | } 71 | 72 | int16_t shtc1_wake_up(void) { 73 | return sensirion_i2c_write_cmd(SHTC1_ADDRESS, SHTC3_CMD_WAKEUP); 74 | } 75 | 76 | int16_t shtc1_measure_blocking_read(int32_t* temperature, int32_t* humidity) { 77 | int16_t ret; 78 | 79 | ret = shtc1_measure(); 80 | if (ret) 81 | return ret; 82 | #if !defined(USE_SENSIRION_CLOCK_STRETCHING) || !USE_SENSIRION_CLOCK_STRETCHING 83 | sensirion_sleep_usec(SHTC1_MEASUREMENT_DURATION_USEC); 84 | #endif /* USE_SENSIRION_CLOCK_STRETCHING */ 85 | return shtc1_read(temperature, humidity); 86 | } 87 | 88 | int16_t shtc1_measure(void) { 89 | return sensirion_i2c_write_cmd(SHTC1_ADDRESS, shtc1_cmd_measure); 90 | } 91 | 92 | int16_t shtc1_read(int32_t* temperature, int32_t* humidity) { 93 | uint16_t words[2]; 94 | int16_t ret = sensirion_i2c_read_words(SHTC1_ADDRESS, words, 95 | SENSIRION_NUM_WORDS(words)); 96 | /** 97 | * formulas for conversion of the sensor signals, optimized for fixed point 98 | * algebra: 99 | * Temperature = 175 * S_T / 2^16 - 45 100 | * Relative Humidity = 100 * S_RH / 2^16 101 | */ 102 | *temperature = ((21875 * (int32_t)words[0]) >> 13) - 45000; 103 | *humidity = ((12500 * (int32_t)words[1]) >> 13); 104 | 105 | return ret; 106 | } 107 | 108 | int16_t shtc1_probe(void) { 109 | uint32_t serial; 110 | 111 | (void)shtc1_wake_up(); /* Try to wake up the sensor, ignore return value */ 112 | return shtc1_read_serial(&serial); 113 | } 114 | 115 | void shtc1_enable_low_power_mode(uint8_t enable_low_power_mode) { 116 | shtc1_cmd_measure = 117 | enable_low_power_mode ? SHTC1_CMD_MEASURE_LPM : SHTC1_CMD_MEASURE_HPM; 118 | } 119 | 120 | int16_t shtc1_read_serial(uint32_t* serial) { 121 | int16_t ret; 122 | const uint16_t tx_words[] = {0x007B}; 123 | uint16_t serial_words[SENSIRION_NUM_WORDS(*serial)]; 124 | 125 | ret = sensirion_i2c_write_cmd_with_args(SHTC1_ADDRESS, 0xC595, tx_words, 126 | SENSIRION_NUM_WORDS(tx_words)); 127 | if (ret) 128 | return ret; 129 | 130 | sensirion_sleep_usec(SHTC1_CMD_DURATION_USEC); 131 | 132 | ret = sensirion_i2c_delayed_read_cmd( 133 | SHTC1_ADDRESS, 0xC7F7, SHTC1_CMD_DURATION_USEC, &serial_words[0], 1); 134 | if (ret) 135 | return ret; 136 | 137 | ret = sensirion_i2c_delayed_read_cmd( 138 | SHTC1_ADDRESS, 0xC7F7, SHTC1_CMD_DURATION_USEC, &serial_words[1], 1); 139 | if (ret) 140 | return ret; 141 | 142 | *serial = ((uint32_t)serial_words[0] << 16) | serial_words[1]; 143 | return 0; 144 | } 145 | 146 | const char* shtc1_get_driver_version(void) { 147 | return SHT_DRV_VERSION_STR; 148 | } 149 | 150 | uint8_t shtc1_get_configured_address(void) { 151 | return SHTC1_ADDRESS; 152 | } 153 | -------------------------------------------------------------------------------- /shtc1/shtc1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * \file 34 | * 35 | * \brief Sensirion SHT driver interface 36 | * 37 | * This module provides access to the SHT functionality over a generic I2C 38 | * interface. It supports measurements without clock stretching only. 39 | */ 40 | 41 | #ifndef SHTC1_H 42 | #define SHTC1_H 43 | 44 | #include "sensirion_arch_config.h" 45 | #include "sensirion_i2c.h" 46 | #include "sht_git_version.h" 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | #define STATUS_OK 0 53 | #define STATUS_ERR_BAD_DATA (-1) 54 | #define STATUS_CRC_FAIL (-2) 55 | #define STATUS_UNKNOWN_DEVICE (-3) 56 | #define SHTC1_MEASUREMENT_DURATION_USEC 14400 57 | 58 | /** 59 | * Detects if a sensor is connected by reading out the ID register. 60 | * If the sensor does not answer or if the answer is not the expected value, 61 | * the test fails. 62 | * 63 | * @return 0 if a sensor was detected 64 | */ 65 | int16_t shtc1_probe(void); 66 | 67 | /** 68 | * Starts a measurement and then reads out the results. This function blocks 69 | * while the measurement is in progress. The duration of the measurement depends 70 | * on the sensor in use, please consult the datasheet. 71 | * Temperature is returned in [degree Celsius], multiplied by 1000, 72 | * and relative humidity in [percent relative humidity], multiplied by 1000. 73 | * 74 | * @param temperature the address for the result of the temperature 75 | * measurement 76 | * @param humidity the address for the result of the relative humidity 77 | * measurement 78 | * @return 0 if the command was successful, else an error code. 79 | */ 80 | int16_t shtc1_measure_blocking_read(int32_t* temperature, int32_t* humidity); 81 | 82 | /** 83 | * Starts a measurement in high precision mode. Use shtc1_read() to read out the 84 | * values, once the measurement is done. The duration of the measurement depends 85 | * on the sensor in use, please consult the datasheet. 86 | * 87 | * @return 0 if the command was successful, else an error code. 88 | */ 89 | int16_t shtc1_measure(void); 90 | 91 | /** 92 | * Reads out the results of a measurement that was previously started by 93 | * shtc1_measure(). If the measurement is still in progress, this function 94 | * returns an error. 95 | * Temperature is returned in [degree Celsius], multiplied by 1000, 96 | * and relative humidity in [percent relative humidity], multiplied by 1000. 97 | * 98 | * @param temperature the address for the result of the temperature 99 | * measurement 100 | * @param humidity the address for the result of the relative humidity 101 | * measurement 102 | * @return 0 if the command was successful, else an error code. 103 | */ 104 | int16_t shtc1_read(int32_t* temperature, int32_t* humidity); 105 | 106 | /** 107 | * Send the sensor to sleep, if supported. 108 | * 109 | * Note: DESPITE THE NAME, THIS COMMAND IS ONLY AVAILABLE FOR THE SHTC3 110 | * 111 | * Usage: 112 | * ``` 113 | * int16_t ret; 114 | * int32_t temperature, humidity; 115 | * ret = shtc1_wake_up(); 116 | * if (ret) { 117 | * // error waking up 118 | * } 119 | * ret = shtc1_measure_blocking_read(&temperature, &humidity); 120 | * if (ret) { 121 | * // error measuring 122 | * } 123 | * ret = shtc1_sleep(); 124 | * if (ret) { 125 | * // error sending sensor to sleep 126 | * } 127 | * ``` 128 | * 129 | * @return 0 if the command was successful, else an error code. 130 | */ 131 | int16_t shtc1_sleep(void); 132 | 133 | /** 134 | * Wake the sensor from sleep 135 | * 136 | * Note: DESPITE THE NAME, THIS COMMAND IS ONLY AVAILABLE FOR THE SHTC3 137 | * 138 | * Usage: 139 | * ``` 140 | * int16_t ret; 141 | * int32_t temperature, humidity; 142 | * ret = shtc1_wake_up(); 143 | * if (ret) { 144 | * // error waking up 145 | * } 146 | * ret = shtc1_measure_blocking_read(&temperature, &humidity); 147 | * if (ret) { 148 | * // error measuring 149 | * } 150 | * ret = shtc1_sleep(); 151 | * if (ret) { 152 | * // error sending sensor to sleep 153 | * } 154 | * ``` 155 | * 156 | * @return 0 if the command was successful, else an error code. 157 | */ 158 | int16_t shtc1_wake_up(void); 159 | 160 | /** 161 | * Enable or disable the SHT's low power mode 162 | * 163 | * @param enable_low_power_mode 1 to enable low power mode, 0 to disable 164 | */ 165 | void shtc1_enable_low_power_mode(uint8_t enable_low_power_mode); 166 | 167 | /** 168 | * Read out the serial number 169 | * 170 | * @param serial the address for the result of the serial number 171 | * @return 0 if the command was successful, else an error code. 172 | */ 173 | int16_t shtc1_read_serial(uint32_t* serial); 174 | 175 | /** 176 | * Return the driver version 177 | * 178 | * @return Driver version string 179 | */ 180 | const char* shtc1_get_driver_version(void); 181 | 182 | /** 183 | * Returns the configured SHT address. 184 | * 185 | * @return The configured i2c address 186 | */ 187 | uint8_t shtc1_get_configured_address(void); 188 | 189 | #ifdef __cplusplus 190 | } 191 | #endif 192 | 193 | #endif /* SHTC1_H */ 194 | -------------------------------------------------------------------------------- /sht3x/sht3x.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * \file 34 | * 35 | * \brief Sensirion SHT driver interface 36 | * 37 | * This module provides access to the SHT functionality over a generic I2C 38 | * interface. It supports measurements without clock stretching only. 39 | */ 40 | 41 | #ifndef SHT3X_H 42 | #define SHT3X_H 43 | 44 | #include "sensirion_arch_config.h" 45 | #include "sensirion_i2c.h" 46 | #include "sht_git_version.h" 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | #define STATUS_OK 0 53 | #define STATUS_ERR_BAD_DATA (-1) 54 | #define STATUS_CRC_FAIL (-2) 55 | #define STATUS_UNKNOWN_DEVICE (-3) 56 | #define STATUS_ERR_INVALID_PARAMS (-4) 57 | #define SHT3X_MEASUREMENT_DURATION_USEC 15000 58 | 59 | /* status word macros */ 60 | #define SHT3X_IS_ALRT_PENDING(status) (((status)&0x8000U) != 0U) 61 | #define SHT3X_IS_ALRT_RH_TRACK(status) (((status)&0x0800) != 0U) 62 | #define SHT3X_IS_ALRT_T_TRACK(status) (((status)&0x0400U) != 0U) 63 | #define SHT3X_IS_SYSTEM_RST_DETECT(status) (((status)&0x0010U) != 0U) 64 | #define SHT3X_IS_LAST_CRC_FAIL(status) (((status)&0x0001U) != 0U) 65 | 66 | /** 67 | * @brief SHT3x I2C 7-bit address option 68 | */ 69 | typedef enum _sht3x_i2c_addr { 70 | SHT3X_I2C_ADDR_DFLT = 0x44, 71 | SHT3X_I2C_ADDR_ALT = 0x45 72 | } sht3x_i2c_addr_t; 73 | 74 | /** 75 | * @brief SHT3x measurment mode options (Low, Medium and High rerefresh rates) 76 | */ 77 | typedef enum _sht3x_measurement_mode { 78 | SHT3X_MEAS_MODE_LPM, /*low power mode*/ 79 | SHT3X_MEAS_MODE_MPM, /*medium power mode*/ 80 | SHT3X_MEAS_MODE_HPM /*high power mode*/ 81 | } sht3x_measurement_mode_t; 82 | 83 | /** 84 | * @brief SHT3x Alert Thresholds 85 | */ 86 | typedef enum _sht3x_alert_thd { 87 | SHT3X_HIALRT_SET, 88 | SHT3X_HIALRT_CLR, 89 | SHT3X_LOALRT_CLR, 90 | SHT3X_LOALRT_SET, 91 | } sht3x_alert_thd_t; 92 | 93 | /** 94 | * @brief Detects if a sensor is connected by reading out the ID register. 95 | * If the sensor does not answer or if the answer is not the expected value, 96 | * the test fails. 97 | * 98 | * @param[in] addr the sensor address 99 | * 100 | * @return 0 if a sensor was detected 101 | */ 102 | int16_t sht3x_probe(sht3x_i2c_addr_t addr); 103 | 104 | /** 105 | * @brief Read the sensor status word 106 | * 107 | * @param[in] addr the sensor address 108 | * @param[out] status the address for the result of the status word 109 | * 110 | * @return 0 if the command was successful, else an error code 111 | */ 112 | int16_t sht3x_get_status(sht3x_i2c_addr_t addr, uint16_t* status); 113 | 114 | /** 115 | * @brief Clear the status register alert flags 116 | * 117 | * @param[in] addr the sensor address 118 | * 119 | * @return 0 if the command was successful, else an error code 120 | */ 121 | int16_t sht3x_clear_status(sht3x_i2c_addr_t addr); 122 | 123 | /** 124 | * @brief Starts a measurement and then reads out the results. This function 125 | * blocks while the measurement is in progress. The duration of the measurement 126 | * depends on the sensor in use, please consult the datasheet. Temperature is 127 | * returned in [degree Celsius], multiplied by 1000, and relative humidity in 128 | * [percent relative humidity], multiplied by 1000. 129 | * 130 | * @param[in] addr the sensor address 131 | * @param[out] temperature the address for the result of the temperature 132 | * measurement 133 | * @param[out] humidity the address for the result of the relative humidity 134 | * measurement 135 | * 136 | * @return 0 if the command was successful, else an error code. 137 | */ 138 | int16_t sht3x_measure_blocking_read(sht3x_i2c_addr_t addr, int32_t* temperature, 139 | int32_t* humidity); 140 | 141 | /** 142 | * @brief Starts a measurement in high precision mode. Use sht3x_read() to read 143 | * out the values, once the measurement is done. The duration of the measurement 144 | * depends on the sensor in use, please consult the datasheet. 145 | * 146 | * @param[in] addr the sensor address 147 | * 148 | * @return 0 if the command was successful, else an error code. 149 | */ 150 | int16_t sht3x_measure(sht3x_i2c_addr_t addr); 151 | 152 | /** 153 | * @brief Reads out the results of a measurement that was previously started by 154 | * sht3x_measure(). If the measurement is still in progress, this function 155 | * returns an error. 156 | * Temperature is returned in [degree Celsius], multiplied by 1000, 157 | * and relative humidity in [percent relative humidity], multiplied by 1000. 158 | * 159 | * @param[in] addr the sensor address 160 | * @param[out] temperature the address for the result of the temperature 161 | * measurement 162 | * @param[out] humidity the address for the result of the relative humidity 163 | * measurement 164 | * 165 | * @return 0 if the command was successful, else an error code. 166 | */ 167 | int16_t sht3x_read(sht3x_i2c_addr_t addr, int32_t* temperature, 168 | int32_t* humidity); 169 | 170 | /** 171 | * @brief Enable or disable the SHT's low power mode 172 | * 173 | * @param[in] enable_low_power_mode 1 to enable low power mode, 0 to disable 174 | */ 175 | void sht3x_enable_low_power_mode(uint8_t enable_low_power_mode); 176 | 177 | /** 178 | * @brief Set the desired sensor's operating power mode 179 | * 180 | * @param[in] mode power mode selector 181 | */ 182 | void sht3x_set_power_mode(sht3x_measurement_mode_t mode); 183 | 184 | /** 185 | * @brief Read out the serial number 186 | * 187 | * @param[in] addr the sensor address 188 | * @param[out] serial the address for the result of the serial number 189 | * 190 | * @return 0 if the command was successful, else an error code. 191 | */ 192 | int16_t sht3x_read_serial(sht3x_i2c_addr_t addr, uint32_t* serial); 193 | 194 | /** 195 | * @brief Return the driver version 196 | * 197 | * @return Driver version string 198 | */ 199 | const char* sht3x_get_driver_version(void); 200 | 201 | /** 202 | * @brief Set target temperature and humidity alert threshold 203 | * 204 | * @param[in] addr the sensor address 205 | * @param[in] thd target alert threshold to be edited 206 | * @param[in] humidity humidity threshold in 1000*%RH 207 | * @param[in] temperature temperature threshold in 1000*°C 208 | * 209 | * @return 0 if the command was successful, else an error code. 210 | */ 211 | int16_t sht3x_set_alert_thd(sht3x_i2c_addr_t addr, sht3x_alert_thd_t thd, 212 | uint32_t humidity, int32_t temperature); 213 | 214 | /** 215 | * @brief Get target temperature and humidity alert threshold 216 | * 217 | * @param[in] addr the sensor address 218 | * @param[in] thd target alert threshold to be edited 219 | * @param[out] humidity address for the result humidity thd in 1000*%RH 220 | * @param[out] temperature address for the result temperature thd in 1000*°C 221 | * 222 | * @return 0 if the command was successful, else an error code. 223 | */ 224 | int16_t sht3x_get_alert_thd(sht3x_i2c_addr_t addr, sht3x_alert_thd_t thd, 225 | int32_t* humidity, int32_t* temperature); 226 | 227 | /** 228 | * @brief converts temperature from ADC ticks 229 | * 230 | * @param tick sensor ADC ticks 231 | * @param temperature temperature value in T°C*1000 232 | */ 233 | void tick_to_temperature(uint16_t tick, int32_t* temperature); 234 | 235 | /** 236 | * @brief converts humidity from ADC ticks 237 | * 238 | * @param tick sensor ADC ticks 239 | * @param humidity humidity value in %*1000 240 | */ 241 | void tick_to_humidity(uint16_t tick, int32_t* humidity); 242 | 243 | /** 244 | * @brief converts temperature to ADC ticks 245 | * 246 | * @param temperature temperature value in T°C*1000 247 | * @param tick sensor ADC ticks 248 | */ 249 | void temperature_to_tick(int32_t temperature, uint16_t* tick); 250 | 251 | /** 252 | * @brief converts humidity to ADC ticks 253 | * 254 | * @param humidity humidity value in %*1000 255 | * @param tick sensor ADC ticks 256 | */ 257 | void humidity_to_tick(int32_t humidity, uint16_t* tick); 258 | 259 | #ifdef __cplusplus 260 | } 261 | #endif 262 | 263 | #endif /* SHT3X_H */ 264 | -------------------------------------------------------------------------------- /sht3x/sht3x.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Sensirion AG 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * * Neither the name of Sensirion AG nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 23 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /** 33 | * \file 34 | * 35 | * \brief Sensirion SHT3x driver implementation 36 | * 37 | * This module provides access to the SHT3x functionality over a generic I2C 38 | * interface. It supports measurements without clock stretching only. 39 | */ 40 | 41 | #include "sht3x.h" 42 | #include "sensirion_arch_config.h" 43 | #include "sensirion_common.h" 44 | #include "sensirion_i2c.h" 45 | 46 | /* all measurement commands return T (CRC) RH (CRC) */ 47 | #if USE_SENSIRION_CLOCK_STRETCHING 48 | #define SHT3X_CMD_MEASURE_HPM 0x2C06 49 | #define SHT3X_CMD_MEASURE_MPM 0x2C0D 50 | #define SHT3X_CMD_MEASURE_LPM 0x2C10 51 | #else /* USE_SENSIRION_CLOCK_STRETCHING */ 52 | #define SHT3X_CMD_MEASURE_HPM 0x2400 53 | #define SHT3X_CMD_MEASURE_MPM 0x240B 54 | #define SHT3X_CMD_MEASURE_LPM 0x2416 55 | #endif /* USE_SENSIRION_CLOCK_STRETCHING */ 56 | 57 | #define SHT3X_HUMIDITY_LIMIT_MSK 0xFE00U 58 | #define SHT3X_TEMPERATURE_LIMIT_MSK 0x01FFU 59 | 60 | static const uint16_t SHT3X_CMD_READ_STATUS_REG = 0xF32D; 61 | static const uint16_t SHT3X_CMD_CLR_STATUS_REG = 0x3041; 62 | static const uint16_t SHT3X_CMD_READ_SERIAL_ID = 0x3780; 63 | static const uint16_t SHT3X_CMD_DURATION_USEC = 1000; 64 | /* read commands for the alert settings */ 65 | static const uint16_t SHT3X_CMD_READ_HIALRT_LIM_SET = 0xE11F; 66 | static const uint16_t SHT3X_CMD_READ_HIALRT_LIM_CLR = 0xE114; 67 | static const uint16_t SHT3X_CMD_READ_LOALRT_LIM_CLR = 0xE109; 68 | static const uint16_t SHT3X_CMD_READ_LOALRT_LIM_SET = 0xE102; 69 | /* write commands for the alert settings */ 70 | static const uint16_t SHT3X_CMD_WRITE_HIALRT_LIM_SET = 0x611D; 71 | static const uint16_t SHT3X_CMD_WRITE_HIALRT_LIM_CLR = 0x6116; 72 | static const uint16_t SHT3X_CMD_WRITE_LOALRT_LIM_CLR = 0x610B; 73 | static const uint16_t SHT3X_CMD_WRITE_LOALRT_LIM_SET = 0x6100; 74 | 75 | static uint16_t sht3x_cmd_measure = SHT3X_CMD_MEASURE_HPM; 76 | 77 | int16_t sht3x_measure_blocking_read(sht3x_i2c_addr_t addr, int32_t* temperature, 78 | int32_t* humidity) { 79 | int16_t ret = sht3x_measure(addr); 80 | if (ret == STATUS_OK) { 81 | #if !defined(USE_SENSIRION_CLOCK_STRETCHING) || !USE_SENSIRION_CLOCK_STRETCHING 82 | sensirion_sleep_usec(SHT3X_MEASUREMENT_DURATION_USEC); 83 | #endif /* USE_SENSIRION_CLOCK_STRETCHING */ 84 | ret = sht3x_read(addr, temperature, humidity); 85 | } 86 | return ret; 87 | } 88 | 89 | int16_t sht3x_measure(sht3x_i2c_addr_t addr) { 90 | return sensirion_i2c_write_cmd(addr, sht3x_cmd_measure); 91 | } 92 | 93 | int16_t sht3x_read(sht3x_i2c_addr_t addr, int32_t* temperature, 94 | int32_t* humidity) { 95 | uint16_t words[2]; 96 | int16_t ret = 97 | sensirion_i2c_read_words(addr, words, SENSIRION_NUM_WORDS(words)); 98 | /** 99 | * formulas for conversion of the sensor signals, optimized for fixed point 100 | * algebra: Temperature = 175 * S_T / 2^16 - 45 101 | * Relative Humidity = * 100 * S_RH / 2^16 102 | */ 103 | tick_to_temperature(words[0], temperature); 104 | tick_to_humidity(words[1], humidity); 105 | 106 | return ret; 107 | } 108 | 109 | int16_t sht3x_probe(sht3x_i2c_addr_t addr) { 110 | uint16_t status; 111 | return sensirion_i2c_delayed_read_cmd(addr, SHT3X_CMD_READ_STATUS_REG, 112 | SHT3X_CMD_DURATION_USEC, &status, 1); 113 | } 114 | 115 | int16_t sht3x_get_status(sht3x_i2c_addr_t addr, uint16_t* status) { 116 | return sensirion_i2c_delayed_read_cmd(addr, SHT3X_CMD_READ_STATUS_REG, 117 | SHT3X_CMD_DURATION_USEC, status, 1); 118 | } 119 | 120 | int16_t sht3x_clear_status(sht3x_i2c_addr_t addr) { 121 | return sensirion_i2c_write_cmd(addr, SHT3X_CMD_CLR_STATUS_REG); 122 | } 123 | 124 | void sht3x_enable_low_power_mode(uint8_t enable_low_power_mode) { 125 | sht3x_cmd_measure = 126 | enable_low_power_mode ? SHT3X_CMD_MEASURE_LPM : SHT3X_CMD_MEASURE_HPM; 127 | } 128 | 129 | void sht3x_set_power_mode(sht3x_measurement_mode_t mode) { 130 | 131 | switch (mode) { 132 | case SHT3X_MEAS_MODE_LPM: { 133 | sht3x_cmd_measure = SHT3X_CMD_MEASURE_LPM; 134 | break; 135 | } 136 | case SHT3X_MEAS_MODE_MPM: { 137 | sht3x_cmd_measure = SHT3X_CMD_MEASURE_MPM; 138 | break; 139 | } 140 | case SHT3X_MEAS_MODE_HPM: { 141 | sht3x_cmd_measure = SHT3X_CMD_MEASURE_HPM; 142 | break; 143 | } 144 | default: { 145 | sht3x_cmd_measure = SHT3X_CMD_MEASURE_HPM; 146 | break; 147 | } 148 | } 149 | } 150 | 151 | int16_t sht3x_read_serial(sht3x_i2c_addr_t addr, uint32_t* serial) { 152 | int16_t ret; 153 | 154 | ret = sensirion_i2c_write_cmd(addr, SHT3X_CMD_READ_SERIAL_ID); 155 | sensirion_sleep_usec(SHT3X_CMD_DURATION_USEC); 156 | 157 | if (ret == STATUS_OK) { 158 | uint8_t serial_bytes[4]; 159 | ret = sensirion_i2c_read_words_as_bytes( 160 | addr, serial_bytes, SENSIRION_NUM_WORDS(serial_bytes)); 161 | *serial = sensirion_bytes_to_uint32_t(serial_bytes); 162 | } 163 | return ret; 164 | } 165 | 166 | const char* sht3x_get_driver_version(void) { 167 | return SHT_DRV_VERSION_STR; 168 | } 169 | 170 | int16_t sht3x_set_alert_thd(sht3x_i2c_addr_t addr, sht3x_alert_thd_t thd, 171 | uint32_t humidity, int32_t temperature) { 172 | int16_t ret; 173 | uint16_t rawT; 174 | uint16_t rawRH; 175 | uint16_t limitVal = 0U; 176 | 177 | temperature_to_tick(temperature, &rawT); 178 | humidity_to_tick(humidity, &rawRH); 179 | 180 | /* convert inputs to alert threshold word */ 181 | limitVal = (rawRH & SHT3X_HUMIDITY_LIMIT_MSK); 182 | limitVal |= ((rawT >> 7) & SHT3X_TEMPERATURE_LIMIT_MSK); 183 | 184 | switch (thd) { 185 | case SHT3X_HIALRT_SET: 186 | ret = sensirion_i2c_write_cmd_with_args( 187 | addr, SHT3X_CMD_WRITE_HIALRT_LIM_SET, &limitVal, 1); 188 | break; 189 | 190 | case SHT3X_HIALRT_CLR: 191 | ret = sensirion_i2c_write_cmd_with_args( 192 | addr, SHT3X_CMD_WRITE_HIALRT_LIM_CLR, &limitVal, 1); 193 | break; 194 | 195 | case SHT3X_LOALRT_CLR: 196 | ret = sensirion_i2c_write_cmd_with_args( 197 | addr, SHT3X_CMD_WRITE_LOALRT_LIM_CLR, &limitVal, 1); 198 | break; 199 | 200 | case SHT3X_LOALRT_SET: 201 | ret = sensirion_i2c_write_cmd_with_args( 202 | addr, SHT3X_CMD_WRITE_LOALRT_LIM_SET, &limitVal, 1); 203 | break; 204 | 205 | default: 206 | ret = STATUS_ERR_INVALID_PARAMS; 207 | break; 208 | } 209 | return ret; 210 | } 211 | 212 | int16_t sht3x_get_alert_thd(sht3x_i2c_addr_t addr, sht3x_alert_thd_t thd, 213 | int32_t* humidity, int32_t* temperature) { 214 | 215 | int16_t ret; 216 | uint16_t word; 217 | uint16_t rawT; 218 | uint16_t rawRH; 219 | 220 | switch (thd) { 221 | case SHT3X_HIALRT_SET: 222 | ret = sensirion_i2c_read_cmd(addr, SHT3X_CMD_READ_HIALRT_LIM_SET, 223 | &word, 1); 224 | break; 225 | 226 | case SHT3X_HIALRT_CLR: 227 | ret = sensirion_i2c_read_cmd(addr, SHT3X_CMD_READ_HIALRT_LIM_CLR, 228 | &word, 1); 229 | break; 230 | 231 | case SHT3X_LOALRT_CLR: 232 | ret = sensirion_i2c_read_cmd(addr, SHT3X_CMD_READ_LOALRT_LIM_CLR, 233 | &word, 1); 234 | break; 235 | 236 | case SHT3X_LOALRT_SET: 237 | ret = sensirion_i2c_read_cmd(addr, SHT3X_CMD_READ_LOALRT_LIM_SET, 238 | &word, 1); 239 | break; 240 | 241 | default: 242 | ret = STATUS_ERR_INVALID_PARAMS; 243 | break; 244 | } 245 | 246 | /* convert threshold word to alert settings in 10*%RH & 10*°C */ 247 | rawRH = (word & SHT3X_HUMIDITY_LIMIT_MSK); 248 | rawT = ((word & SHT3X_TEMPERATURE_LIMIT_MSK) << 7); 249 | 250 | tick_to_humidity(rawRH, humidity); 251 | tick_to_temperature(rawT, temperature); 252 | 253 | return ret; 254 | } 255 | 256 | void tick_to_temperature(uint16_t tick, int32_t* temperature) { 257 | *temperature = ((21875 * (int32_t)tick) >> 13) - 45000; 258 | } 259 | 260 | void tick_to_humidity(uint16_t tick, int32_t* humidity) { 261 | *humidity = ((12500 * (int32_t)tick) >> 13); 262 | } 263 | 264 | void temperature_to_tick(int32_t temperature, uint16_t* tick) { 265 | *tick = (uint16_t)((temperature * 12271 + 552195000) >> 15); 266 | } 267 | 268 | void humidity_to_tick(int32_t humidity, uint16_t* tick) { 269 | *tick = (uint16_t)((humidity * 21474) >> 15); 270 | } -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/Source/startup_stm32f10x_md_vl.s: -------------------------------------------------------------------------------- 1 | ;******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 | ;* File Name : startup_stm32f10x_md_vl.s 3 | ;* Author : MCD Application Team 4 | ;* Version : V3.5.0 5 | ;* Date : 11-March-2011 6 | ;* Description : STM32F10x Medium Density Value Line Devices vector table 7 | ;* for MDK-ARM toolchain. 8 | ;* This module performs: 9 | ;* - Set the initial SP 10 | ;* - Set the initial PC == Reset_Handler 11 | ;* - Set the vector table entries with the exceptions ISR address 12 | ;* - Configure the clock system 13 | ;* - Branches to __main in the C library (which eventually 14 | ;* calls main()). 15 | ;* After Reset the CortexM3 processor is in Thread mode, 16 | ;* priority is Privileged, and the Stack is set to Main. 17 | ;* <<< Use Configuration Wizard in Context Menu >>> 18 | ;******************************************************************************* 19 | ; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 20 | ; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 21 | ; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 22 | ; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 23 | ; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 24 | ; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 25 | ;******************************************************************************* 26 | 27 | ; Amount of memory (in bytes) allocated for Stack 28 | ; Tailor this value to your application needs 29 | ; Stack Configuration 30 | ; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> 31 | ; 32 | 33 | Stack_Size EQU 0x00000400 34 | 35 | AREA STACK, NOINIT, READWRITE, ALIGN=3 36 | Stack_Mem SPACE Stack_Size 37 | __initial_sp 38 | 39 | 40 | ; Heap Configuration 41 | ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> 42 | ; 43 | 44 | Heap_Size EQU 0x00000200 45 | 46 | AREA HEAP, NOINIT, READWRITE, ALIGN=3 47 | __heap_base 48 | Heap_Mem SPACE Heap_Size 49 | __heap_limit 50 | 51 | PRESERVE8 52 | THUMB 53 | 54 | 55 | ; Vector Table Mapped to Address 0 at Reset 56 | AREA RESET, DATA, READONLY 57 | EXPORT __Vectors 58 | EXPORT __Vectors_End 59 | EXPORT __Vectors_Size 60 | 61 | __Vectors DCD __initial_sp ; Top of Stack 62 | DCD Reset_Handler ; Reset Handler 63 | DCD NMI_Handler ; NMI Handler 64 | DCD HardFault_Handler ; Hard Fault Handler 65 | DCD MemManage_Handler ; MPU Fault Handler 66 | DCD BusFault_Handler ; Bus Fault Handler 67 | DCD UsageFault_Handler ; Usage Fault Handler 68 | DCD 0 ; Reserved 69 | DCD 0 ; Reserved 70 | DCD 0 ; Reserved 71 | DCD 0 ; Reserved 72 | DCD SVC_Handler ; SVCall Handler 73 | DCD DebugMon_Handler ; Debug Monitor Handler 74 | DCD 0 ; Reserved 75 | DCD PendSV_Handler ; PendSV Handler 76 | DCD SysTick_Handler ; SysTick Handler 77 | 78 | ; External Interrupts 79 | DCD WWDG_IRQHandler ; Window Watchdog 80 | DCD PVD_IRQHandler ; PVD through EXTI Line detect 81 | DCD TAMPER_IRQHandler ; Tamper 82 | DCD RTC_IRQHandler ; RTC 83 | DCD FLASH_IRQHandler ; Flash 84 | DCD RCC_IRQHandler ; RCC 85 | DCD EXTI0_IRQHandler ; EXTI Line 0 86 | DCD EXTI1_IRQHandler ; EXTI Line 1 87 | DCD EXTI2_IRQHandler ; EXTI Line 2 88 | DCD EXTI3_IRQHandler ; EXTI Line 3 89 | DCD EXTI4_IRQHandler ; EXTI Line 4 90 | DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 91 | DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2 92 | DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3 93 | DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4 94 | DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5 95 | DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6 96 | DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7 97 | DCD ADC1_IRQHandler ; ADC1 98 | DCD 0 ; Reserved 99 | DCD 0 ; Reserved 100 | DCD 0 ; Reserved 101 | DCD 0 ; Reserved 102 | DCD EXTI9_5_IRQHandler ; EXTI Line 9..5 103 | DCD TIM1_BRK_TIM15_IRQHandler ; TIM1 Break and TIM15 104 | DCD TIM1_UP_TIM16_IRQHandler ; TIM1 Update and TIM16 105 | DCD TIM1_TRG_COM_TIM17_IRQHandler ; TIM1 Trigger and Commutation and TIM17 106 | DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare 107 | DCD TIM2_IRQHandler ; TIM2 108 | DCD TIM3_IRQHandler ; TIM3 109 | DCD TIM4_IRQHandler ; TIM4 110 | DCD I2C1_EV_IRQHandler ; I2C1 Event 111 | DCD I2C1_ER_IRQHandler ; I2C1 Error 112 | DCD I2C2_EV_IRQHandler ; I2C2 Event 113 | DCD I2C2_ER_IRQHandler ; I2C2 Error 114 | DCD SPI1_IRQHandler ; SPI1 115 | DCD SPI2_IRQHandler ; SPI2 116 | DCD USART1_IRQHandler ; USART1 117 | DCD USART2_IRQHandler ; USART2 118 | DCD USART3_IRQHandler ; USART3 119 | DCD EXTI15_10_IRQHandler ; EXTI Line 15..10 120 | DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line 121 | DCD CEC_IRQHandler ; HDMI-CEC 122 | DCD 0 ; Reserved 123 | DCD 0 ; Reserved 124 | DCD 0 ; Reserved 125 | DCD 0 ; Reserved 126 | DCD 0 ; Reserved 127 | DCD 0 ; Reserved 128 | DCD 0 ; Reserved 129 | DCD 0 ; Reserved 130 | DCD 0 ; Reserved 131 | DCD 0 ; Reserved 132 | DCD 0 ; Reserved 133 | DCD TIM6_DAC_IRQHandler ; TIM6 and DAC underrun 134 | DCD TIM7_IRQHandler ; TIM7 135 | __Vectors_End 136 | 137 | __Vectors_Size EQU __Vectors_End - __Vectors 138 | 139 | AREA |.text|, CODE, READONLY 140 | 141 | ; Reset handler 142 | Reset_Handler PROC 143 | EXPORT Reset_Handler [WEAK] 144 | IMPORT __main 145 | IMPORT SystemInit 146 | LDR R0, =SystemInit 147 | BLX R0 148 | LDR R0, =__main 149 | BX R0 150 | ENDP 151 | 152 | ; Dummy Exception Handlers (infinite loops which can be modified) 153 | 154 | NMI_Handler PROC 155 | EXPORT NMI_Handler [WEAK] 156 | B . 157 | ENDP 158 | HardFault_Handler\ 159 | PROC 160 | EXPORT HardFault_Handler [WEAK] 161 | B . 162 | ENDP 163 | MemManage_Handler\ 164 | PROC 165 | EXPORT MemManage_Handler [WEAK] 166 | B . 167 | ENDP 168 | BusFault_Handler\ 169 | PROC 170 | EXPORT BusFault_Handler [WEAK] 171 | B . 172 | ENDP 173 | UsageFault_Handler\ 174 | PROC 175 | EXPORT UsageFault_Handler [WEAK] 176 | B . 177 | ENDP 178 | SVC_Handler PROC 179 | EXPORT SVC_Handler [WEAK] 180 | B . 181 | ENDP 182 | DebugMon_Handler\ 183 | PROC 184 | EXPORT DebugMon_Handler [WEAK] 185 | B . 186 | ENDP 187 | PendSV_Handler PROC 188 | EXPORT PendSV_Handler [WEAK] 189 | B . 190 | ENDP 191 | SysTick_Handler PROC 192 | EXPORT SysTick_Handler [WEAK] 193 | B . 194 | ENDP 195 | 196 | Default_Handler PROC 197 | 198 | EXPORT WWDG_IRQHandler [WEAK] 199 | EXPORT PVD_IRQHandler [WEAK] 200 | EXPORT TAMPER_IRQHandler [WEAK] 201 | EXPORT RTC_IRQHandler [WEAK] 202 | EXPORT FLASH_IRQHandler [WEAK] 203 | EXPORT RCC_IRQHandler [WEAK] 204 | EXPORT EXTI0_IRQHandler [WEAK] 205 | EXPORT EXTI1_IRQHandler [WEAK] 206 | EXPORT EXTI2_IRQHandler [WEAK] 207 | EXPORT EXTI3_IRQHandler [WEAK] 208 | EXPORT EXTI4_IRQHandler [WEAK] 209 | EXPORT DMA1_Channel1_IRQHandler [WEAK] 210 | EXPORT DMA1_Channel2_IRQHandler [WEAK] 211 | EXPORT DMA1_Channel3_IRQHandler [WEAK] 212 | EXPORT DMA1_Channel4_IRQHandler [WEAK] 213 | EXPORT DMA1_Channel5_IRQHandler [WEAK] 214 | EXPORT DMA1_Channel6_IRQHandler [WEAK] 215 | EXPORT DMA1_Channel7_IRQHandler [WEAK] 216 | EXPORT ADC1_IRQHandler [WEAK] 217 | EXPORT EXTI9_5_IRQHandler [WEAK] 218 | EXPORT TIM1_BRK_TIM15_IRQHandler [WEAK] 219 | EXPORT TIM1_UP_TIM16_IRQHandler [WEAK] 220 | EXPORT TIM1_TRG_COM_TIM17_IRQHandler [WEAK] 221 | EXPORT TIM1_CC_IRQHandler [WEAK] 222 | EXPORT TIM2_IRQHandler [WEAK] 223 | EXPORT TIM3_IRQHandler [WEAK] 224 | EXPORT TIM4_IRQHandler [WEAK] 225 | EXPORT I2C1_EV_IRQHandler [WEAK] 226 | EXPORT I2C1_ER_IRQHandler [WEAK] 227 | EXPORT I2C2_EV_IRQHandler [WEAK] 228 | EXPORT I2C2_ER_IRQHandler [WEAK] 229 | EXPORT SPI1_IRQHandler [WEAK] 230 | EXPORT SPI2_IRQHandler [WEAK] 231 | EXPORT USART1_IRQHandler [WEAK] 232 | EXPORT USART2_IRQHandler [WEAK] 233 | EXPORT USART3_IRQHandler [WEAK] 234 | EXPORT EXTI15_10_IRQHandler [WEAK] 235 | EXPORT RTCAlarm_IRQHandler [WEAK] 236 | EXPORT CEC_IRQHandler [WEAK] 237 | EXPORT TIM6_DAC_IRQHandler [WEAK] 238 | EXPORT TIM7_IRQHandler [WEAK] 239 | 240 | WWDG_IRQHandler 241 | PVD_IRQHandler 242 | TAMPER_IRQHandler 243 | RTC_IRQHandler 244 | FLASH_IRQHandler 245 | RCC_IRQHandler 246 | EXTI0_IRQHandler 247 | EXTI1_IRQHandler 248 | EXTI2_IRQHandler 249 | EXTI3_IRQHandler 250 | EXTI4_IRQHandler 251 | DMA1_Channel1_IRQHandler 252 | DMA1_Channel2_IRQHandler 253 | DMA1_Channel3_IRQHandler 254 | DMA1_Channel4_IRQHandler 255 | DMA1_Channel5_IRQHandler 256 | DMA1_Channel6_IRQHandler 257 | DMA1_Channel7_IRQHandler 258 | ADC1_IRQHandler 259 | EXTI9_5_IRQHandler 260 | TIM1_BRK_TIM15_IRQHandler 261 | TIM1_UP_TIM16_IRQHandler 262 | TIM1_TRG_COM_TIM17_IRQHandler 263 | TIM1_CC_IRQHandler 264 | TIM2_IRQHandler 265 | TIM3_IRQHandler 266 | TIM4_IRQHandler 267 | I2C1_EV_IRQHandler 268 | I2C1_ER_IRQHandler 269 | I2C2_EV_IRQHandler 270 | I2C2_ER_IRQHandler 271 | SPI1_IRQHandler 272 | SPI2_IRQHandler 273 | USART1_IRQHandler 274 | USART2_IRQHandler 275 | USART3_IRQHandler 276 | EXTI15_10_IRQHandler 277 | RTCAlarm_IRQHandler 278 | CEC_IRQHandler 279 | TIM6_DAC_IRQHandler 280 | TIM7_IRQHandler 281 | B . 282 | 283 | ENDP 284 | 285 | ALIGN 286 | 287 | ;******************************************************************************* 288 | ; User Stack and Heap initialization 289 | ;******************************************************************************* 290 | IF :DEF:__MICROLIB 291 | 292 | EXPORT __initial_sp 293 | EXPORT __heap_base 294 | EXPORT __heap_limit 295 | 296 | ELSE 297 | 298 | IMPORT __use_two_region_memory 299 | EXPORT __user_initial_stackheap 300 | 301 | __user_initial_stackheap 302 | 303 | LDR R0, = Heap_Mem 304 | LDR R1, =(Stack_Mem + Stack_Size) 305 | LDR R2, = (Heap_Mem + Heap_Size) 306 | LDR R3, = Stack_Mem 307 | BX LR 308 | 309 | ALIGN 310 | 311 | ENDIF 312 | 313 | END 314 | 315 | ;******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE***** 316 | -------------------------------------------------------------------------------- /sample-projects/shtc3-stm32-uvision/shtc3-stm32.uvprojx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2.1 5 | 6 |
### uVision Project, (C) Keil Software
7 | 8 | 9 | 10 | STM32-Discovery 11 | 0x4 12 | ARM-ADS 13 | 5060422::V5.06 update 4 (build 422)::ARMCC 14 | 0 15 | 16 | 17 | STM32F100RB 18 | STMicroelectronics 19 | Keil.STM32F1xx_DFP.2.2.0 20 | http://www.keil.com/pack/ 21 | IRAM(0x20000000,0x00002000) IROM(0x08000000,0x00020000) CPUTYPE("Cortex-M3") CLOCK(12000000) ELITTLE 22 | 23 | 24 | UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128 -FS08000000 -FL020000 -FP0($$Device:STM32F100RB$Flash\STM32F10x_128.FLM)) 25 | 5086 26 | $$Device:STM32F100RB$Device\Include\stm32f10x.h 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | $$Device:STM32F100RB$SVD\STM32F100xx.svd 37 | 0 38 | 0 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 46 | 0 47 | 0 48 | 0 49 | 1 50 | 51 | .\Objects\ 52 | SHTC3_SampleCode 53 | 1 54 | 0 55 | 1 56 | 1 57 | 1 58 | .\Listings\ 59 | 1 60 | 0 61 | 0 62 | 63 | 0 64 | 0 65 | 66 | 67 | 0 68 | 0 69 | 0 70 | 0 71 | 72 | 73 | 0 74 | 0 75 | 76 | 77 | 0 78 | 0 79 | 0 80 | 0 81 | 82 | 83 | 0 84 | 0 85 | 86 | 87 | 0 88 | 0 89 | 0 90 | 0 91 | 92 | 0 93 | 94 | 95 | 96 | 0 97 | 0 98 | 0 99 | 0 100 | 0 101 | 1 102 | 0 103 | 0 104 | 0 105 | 0 106 | 3 107 | 108 | 109 | 1 110 | 111 | 112 | SARMCM3.DLL 113 | -REMAP 114 | DCM.DLL 115 | -pCM3 116 | SARMCM3.DLL 117 | 118 | TCM.DLL 119 | -pCM3 120 | 121 | 122 | 123 | 1 124 | 0 125 | 0 126 | 0 127 | 16 128 | 129 | 130 | 131 | 132 | 1 133 | 0 134 | 0 135 | 1 136 | 1 137 | 4096 138 | 139 | 1 140 | BIN\UL2CM3.DLL 141 | "" () 142 | 143 | 144 | 145 | 146 | 0 147 | 148 | 149 | 150 | 0 151 | 1 152 | 1 153 | 1 154 | 1 155 | 1 156 | 1 157 | 1 158 | 0 159 | 1 160 | 1 161 | 0 162 | 1 163 | 1 164 | 0 165 | 0 166 | 1 167 | 1 168 | 1 169 | 1 170 | 1 171 | 1 172 | 1 173 | 1 174 | 1 175 | 0 176 | 0 177 | "Cortex-M3" 178 | 179 | 0 180 | 0 181 | 0 182 | 1 183 | 1 184 | 0 185 | 0 186 | 0 187 | 0 188 | 0 189 | 8 190 | 0 191 | 0 192 | 0 193 | 0 194 | 3 195 | 3 196 | 0 197 | 0 198 | 0 199 | 0 200 | 0 201 | 0 202 | 0 203 | 0 204 | 0 205 | 0 206 | 1 207 | 0 208 | 0 209 | 0 210 | 0 211 | 1 212 | 0 213 | 214 | 215 | 0 216 | 0x0 217 | 0x0 218 | 219 | 220 | 0 221 | 0x0 222 | 0x0 223 | 224 | 225 | 0 226 | 0x0 227 | 0x0 228 | 229 | 230 | 0 231 | 0x0 232 | 0x0 233 | 234 | 235 | 0 236 | 0x0 237 | 0x0 238 | 239 | 240 | 0 241 | 0x0 242 | 0x0 243 | 244 | 245 | 0 246 | 0x20000000 247 | 0x2000 248 | 249 | 250 | 1 251 | 0x8000000 252 | 0x20000 253 | 254 | 255 | 0 256 | 0x0 257 | 0x0 258 | 259 | 260 | 1 261 | 0x0 262 | 0x0 263 | 264 | 265 | 1 266 | 0x0 267 | 0x0 268 | 269 | 270 | 1 271 | 0x0 272 | 0x0 273 | 274 | 275 | 1 276 | 0x8000000 277 | 0x20000 278 | 279 | 280 | 1 281 | 0x0 282 | 0x0 283 | 284 | 285 | 0 286 | 0x0 287 | 0x0 288 | 289 | 290 | 0 291 | 0x0 292 | 0x0 293 | 294 | 295 | 0 296 | 0x0 297 | 0x0 298 | 299 | 300 | 0 301 | 0x20000000 302 | 0x2000 303 | 304 | 305 | 0 306 | 0x0 307 | 0x0 308 | 309 | 310 | 311 | 312 | 313 | 1 314 | 1 315 | 0 316 | 0 317 | 0 318 | 0 319 | 0 320 | 0 321 | 0 322 | 0 323 | 0 324 | 0 325 | 0 326 | 1 327 | 0 328 | 0 329 | 0 330 | 0 331 | 0 332 | 0 333 | 0 334 | 0 335 | 0 336 | 337 | 338 | STM32F10X_MD_VL 339 | 340 | .\shtc1 341 | 342 | 343 | 344 | 1 345 | 0 346 | 0 347 | 0 348 | 0 349 | 0 350 | 0 351 | 0 352 | 0 353 | 0 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 1 363 | 0 364 | 0 365 | 0 366 | 1 367 | 0 368 | 0x08000000 369 | 0x20000000 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | StartUp 383 | 384 | 385 | startup_stm32f10x_md_vl.s 386 | 2 387 | .\Source\startup_stm32f10x_md_vl.s 388 | 389 | 390 | 391 | 392 | Source Files 393 | 394 | 395 | main.c 396 | 1 397 | .\Source\main.c 398 | 399 | 400 | system.c 401 | 1 402 | .\Source\system.c 403 | 404 | 405 | sensirion_sw_i2c_implementation.c 406 | 1 407 | .\Source\sensirion_sw_i2c_implementation.c 408 | 409 | 410 | 411 | 412 | shtc1 413 | 414 | 415 | sensirion_common.c 416 | 1 417 | .\shtc1\sensirion_common.c 418 | 419 | 420 | shtc1.c 421 | 1 422 | .\shtc1\shtc1.c 423 | 424 | 425 | sensirion_sw_i2c.c 426 | 1 427 | .\shtc1\sw_i2c\sensirion_sw_i2c.c 428 | 429 | 430 | sht_git_version.c 431 | 1 432 | .\shtc1\sht_git_version.c 433 | 434 | 435 | 436 | 437 | ::CMSIS 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 |
457 | --------------------------------------------------------------------------------