Sensirion SHT21 Sample Code Communication Software


Sensirion SHT21 Sample Code Communication Software - cover page
Brand
SENSIRION
Category
Other Electronics
Document type
Programming Manual
Language
English
Pages
14
File format
PDF
File size
89 KB
Published
11 April, 2012
Updated
29 September, 2023
Model
SHT21
MD5 checksum
DC77174947AFFA9282A287F9BE61D354

About this manual

This document provides a complete set of C source files that demonstrate how to interface a microcontroller with the Sensirion SHT21 (SHT2x family) humidity and temperature sensor. It includes a hardware abstraction layer for I²C communication, sensor driver functions, and example usage in a main program.

The code is organized into modules (system, I2C HAL, sensor driver, display) and shows how to initialize the hardware, read measurements, handle CRC checks, reset the sensor, and retrieve the 64‑bit serial number. It is intended for developers who need a ready‑to‑use reference implementation for the SHT21 sensor.

What's inside

  • Structure and Hierarchy of Code
  • Sample Code
  • SHT2x.h
  • SHT2x.c
  • I2C_HAL.h
  • I2C_HAL.c
  • Preface

Specifications

I²C write address0x80 (128)
I²C read address0x81 (129)
CRC polynomial0x131
Resolution optionsRH 12‑bit / T 14‑bit (0x00), RH 8‑bit / T 12‑bit (0x01), RH 10‑bit / T 13‑bit (0x80), RH 11‑bit / T 11‑bit (0x81)
Heater command0x04 (on), 0x00 (off)

Frequently asked questions

How do I perform a soft reset of the SHT21 sensor?

Call the function SHT2x_SoftReset(), which sends the soft‑reset command over I²C and waits for the sensor to restart.

How can I read the 64‑bit serial number of the sensor?

Use the SHT2x_GetSerialNumber() routine; it reads the serial number from the sensor’s on‑chip memory and returns it in an 8‑byte array.

How do I change the measurement resolution?

Read the user register, mask the resolution bits with SHT2x_RES_MASK, set the desired resolution constant (e.g., SHT2x_RES_10_13BIT), and write the register back with SHT2x_WriteUserRegister().

Download PDF (89 KB)

More SENSIRION Manuals


View all SENSIRION manuals →