Skip to content

About

stts22h platform independent driver based on Rust programming language

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

1 watching

Forks

Latest commit

 

History

28 Commits

Folders and files

Repository files navigation

stts22h-rs

Crates.io BSD 3-Clause licensed

Provides a platform-agnostic, no_std-compatible driver for the ST STTS22H temperature sensor, supporting both I2C and SPI communication interfaces.

Sensor Overview

The STTS22H is a digital temperature sensor that communicates over a 2-wire I²C/SMBus 3.0 serial interface. Thanks to its factory calibration, the STTS22H offers high-end accuracy performance over the entire operating temperature range reaching as low as ±0.5 °C without requiring any further calibration at the application level.

The sensor operating mode is user-configurable and allows selecting between different ODRs (down to 1 Hz) or the one-shot mode for battery saving. In one-shot mode, the sensor current consumption falls to 1.75 µA.

The STTS22H comes in a 6-pin device that supports user-configurable slave addresses. By connecting properly the Addr pin (see Table 2), four different addresses can be specified, thus allowing to have up to four STTS22H sharing the same I²C/SMBus bus line. An interrupt pin is also available to signal the application whenever the user-selectable high or low threshold has been exceeded.

For more info, please visit the device page at https://www.st.com/en/mems-and-sensors/stts22h.html

Installation

Add the driver to your Cargo.toml dependencies:

[dependencies]
stts22h-rs = "2.0.0"

Or, add it directly from the terminal:

cargo add stts22h-rs

Usage

By default, the create exposes the asynchronous API, and it could be included using:

use stts22h_rs::asynchronous as stts22h;
use stts22h::*;
use stts22h::prelude::*;

Blocking API (optional feature)

To use the blocking API instead of the asynchronous one, disable default features and enable the blocking feature in your Cargo.toml

[dependencies]
stts22h-rs = { version = "2.0.0", default-features = false, features = ["blocking"] }

or from the terminal:

cargo add stts22h-rs --no-default-features --features blocking

Then import the blocking API:

use stts22h_rs::blocking as stts22h;
use stts22h::*;
use stts22h::prelude::*;

Create an instance

Create an instance of the driver with the new_<bus> associated function, by passing an I2C (embedded_hal::i2c::I2c) instance and I2C address, or an SPI (embedded_hal::spi::SpiDevice) instance.

An example with I2C:

let mut sensor = Stts22h::new_i2c(i2c, I2CAddress::I2cAddH).unwrap();

Check "Who Am I" Register

This step ensures correct communication with the sensor. It returns a unique ID to verify the sensor's identity.

let whoami = sensor.dev_id_get().unwrap();
if whoami != ID {
    panic!("Invalid sensor ID");
}

Examples Location

Examples are organized in the bsp folder as separate Rust binaries. This structure abstracts board-specific details, enabling board generalization while keeping the examples unchanged.

Currently, the supported board and frameworks are:

  • nucleo-f401re — built on the stm32-rs framework, using a blocking implementation.
  • nucleo-f401re-embassy — uses the embassy asynchronous framework..

More details and instructions are available in bsp/README.md.

Configure

See details in specific examples; the following are common api calls:

// Set Output Data Rate
sensor.temp_data_rate_set(OdrTemp::Odr1Hz).unwrap();

License

Distributed under the BSD-3 Clause license.

More Information: http://www.st.com.

Copyright (C) 2025 STMicroelectronics

About

stts22h platform independent driver based on Rust programming language

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages