DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
sht3x.h File Reference

Sensirion SHT3x temperature / humidity sensor codec (DETWS_ENABLE_SHT3X). More...

#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define SHT3X_CMD_SINGLE_HIGH   0x2400
 high repeatability, no clock stretching
 
#define SHT3X_CMD_SINGLE_MED   0x240B
 medium repeatability
 
#define SHT3X_CMD_SINGLE_LOW   0x2416
 low repeatability
 
#define SHT3X_CMD_SOFT_RESET   0x30A2
 soft reset
 
#define SHT3X_CMD_READ_STATUS   0xF32D
 read the status register
 
#define SHT3X_CMD_HEATER_ON   0x306D
 enable the on-chip heater
 
#define SHT3X_CMD_HEATER_OFF   0x3066
 disable the on-chip heater
 

Functions

uint8_t sht3x_crc8 (const uint8_t *data, size_t len)
 Sensirion CRC-8 (poly 0x31, init 0xFF) over len bytes.
 
int32_t sht3x_temp_mc (uint16_t raw)
 Convert a raw 16-bit temperature tick to milli-degrees Celsius.
 
int32_t sht3x_rh_mpct (uint16_t raw)
 Convert a raw 16-bit humidity tick to milli-percent relative humidity (0..100000).
 
bool sht3x_parse (const uint8_t resp[6], int32_t *temp_mc, int32_t *rh_mpct)
 Decode a six-byte single-shot response (T msb/lsb/crc, RH msb/lsb/crc). Verifies both CRC-8 words, then fills temp_mc and rh_mpct (either may be null).
 
bool sht3x_begin (uint8_t addr)
 Soft-reset the SHT3x at addr over I2C.
 
bool sht3x_read (int32_t *temp_mc, int32_t *rh_mpct)
 Trigger a single-shot high-repeatability measurement, read + verify the six bytes, and return the temperature (milli-C) and humidity (milli-RH).
 

Detailed Description

Sensirion SHT3x temperature / humidity sensor codec (DETWS_ENABLE_SHT3X).

The SHT3x (SHT30 / SHT31 / SHT35) answers a single-shot measurement command with six bytes: a 16-bit temperature word + its CRC-8, then a 16-bit humidity word + its CRC-8. The CRC is the Sensirion CRC-8 (polynomial 0x31, init 0xFF, no reflection, no final XOR; the datasheet check value is 0xBEEF -> 0x92). Raw ticks convert linearly: T[C] = -45 + 175 * raw / 65535 RH[%] = 100 * raw / 65535

To stay heap- and float-printf-free, the results are returned as signed integer milli-units (milli-degrees C, milli-percent RH). The CRC check and the conversion are pure and host-tested; only the command write / data read touches I2C.

A cheap solder-and-bench-test breakout (GY-SHT31 etc.): read it, bridge the reading onto the network as telemetry.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file sht3x.h.

Macro Definition Documentation

◆ SHT3X_CMD_SINGLE_HIGH

#define SHT3X_CMD_SINGLE_HIGH   0x2400

high repeatability, no clock stretching

Definition at line 33 of file sht3x.h.

◆ SHT3X_CMD_SINGLE_MED

#define SHT3X_CMD_SINGLE_MED   0x240B

medium repeatability

Definition at line 34 of file sht3x.h.

◆ SHT3X_CMD_SINGLE_LOW

#define SHT3X_CMD_SINGLE_LOW   0x2416

low repeatability

Definition at line 35 of file sht3x.h.

◆ SHT3X_CMD_SOFT_RESET

#define SHT3X_CMD_SOFT_RESET   0x30A2

soft reset

Definition at line 36 of file sht3x.h.

◆ SHT3X_CMD_READ_STATUS

#define SHT3X_CMD_READ_STATUS   0xF32D

read the status register

Definition at line 37 of file sht3x.h.

◆ SHT3X_CMD_HEATER_ON

#define SHT3X_CMD_HEATER_ON   0x306D

enable the on-chip heater

Definition at line 38 of file sht3x.h.

◆ SHT3X_CMD_HEATER_OFF

#define SHT3X_CMD_HEATER_OFF   0x3066

disable the on-chip heater

Definition at line 39 of file sht3x.h.

Function Documentation

◆ sht3x_crc8()

uint8_t sht3x_crc8 ( const uint8_t *  data,
size_t  len 
)

Sensirion CRC-8 (poly 0x31, init 0xFF) over len bytes.

◆ sht3x_temp_mc()

int32_t sht3x_temp_mc ( uint16_t  raw)

Convert a raw 16-bit temperature tick to milli-degrees Celsius.

◆ sht3x_rh_mpct()

int32_t sht3x_rh_mpct ( uint16_t  raw)

Convert a raw 16-bit humidity tick to milli-percent relative humidity (0..100000).

◆ sht3x_parse()

bool sht3x_parse ( const uint8_t  resp[6],
int32_t *  temp_mc,
int32_t *  rh_mpct 
)

Decode a six-byte single-shot response (T msb/lsb/crc, RH msb/lsb/crc). Verifies both CRC-8 words, then fills temp_mc and rh_mpct (either may be null).

Returns
false if a CRC does not match (a corrupt read).

◆ sht3x_begin()

bool sht3x_begin ( uint8_t  addr)

Soft-reset the SHT3x at addr over I2C.

Returns
true if it acknowledged.

◆ sht3x_read()

bool sht3x_read ( int32_t *  temp_mc,
int32_t *  rh_mpct 
)

Trigger a single-shot high-repeatability measurement, read + verify the six bytes, and return the temperature (milli-C) and humidity (milli-RH).

Returns
false on I2C or CRC error.