14uint8_t
sht3x_crc8(
const uint8_t *data,
size_t len)
17 for (
size_t i = 0; i < len; i++)
20 for (
int b = 0; b < 8; b++)
21 crc = (crc & 0x80) ? (uint8_t)((crc << 1) ^ 0x31) : (uint8_t)(crc << 1);
29 return (int32_t)(-45000 + (int64_t)175000 * raw / 65535);
34 int32_t v = (int32_t)((int64_t)100000 * raw / 65535);
35 return v > 100000 ? 100000 : v;
38bool sht3x_parse(
const uint8_t resp[6], int32_t *temp_mc, int32_t *rh_mpct)
42 uint16_t traw = (uint16_t)(((uint16_t)resp[0] << 8) | resp[1]);
43 uint16_t hraw = (uint16_t)(((uint16_t)resp[3] << 8) | resp[4]);
71bool send_cmd(uint16_t cmd)
73 Wire.beginTransmission(s_sht.addr);
74 Wire.write((uint8_t)(cmd >> 8));
75 Wire.write((uint8_t)(cmd & 0xFF));
76 return Wire.endTransmission() == 0;
89bool sht3x_read(int32_t *temp_mc, int32_t *rh_mpct)
94 if (Wire.requestFrom((
int)s_sht.addr, 6) != 6)
97 for (
int i = 0; i < 6; i++)
98 r[i] = (uint8_t)Wire.read();
User-facing configuration for DeterministicESPAsyncWebServer.
#define DETWS_SHT3X_I2C_ADDR
I2C address of the SHT3x (0x44 with ADDR low; 0x45 with ADDR high).
The one owner of the shared I2C bus bring-up for the peripheral drivers.
void detws_i2c_begin()
Bring up the shared I2C bus on DETWS_I2C_SDA_PIN / DETWS_I2C_SCL_PIN (-1 = default).
Sensirion SHT3x temperature / humidity sensor codec (DETWS_ENABLE_SHT3X).
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,...
#define SHT3X_CMD_SOFT_RESET
soft reset
int32_t sht3x_temp_mc(uint16_t raw)
Convert a raw 16-bit temperature tick to milli-degrees Celsius.
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,...
#define SHT3X_CMD_SINGLE_HIGH
high repeatability, no clock stretching
uint8_t sht3x_crc8(const uint8_t *data, size_t len)
Sensirion CRC-8 (poly 0x31, init 0xFF) over len bytes.