Skip to main content

Crate asm330lhhx_rs

Crate asm330lhhx_rs 

Source
Expand description

§asm330lhhx-rs

Crates.io BSD 3-Clause licensed

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

§Sensor Overview

The ASM330LHHX is a 6-axis IMU featuring a 3-axis digital accelerometer and a 3-axis digital gyroscope with an extended temperature range up to +105°C, designed to address automotive nonsafety applications.

ST’s family of MEMS sensor modules leverages the robust and mature manufacturing processes already used for the production of micromachined accelerometers and gyroscopes to serve both the automotive and consumer markets. The ASM330LHHX is AEC-Q100 compliant and industrialized through a dedicated MEMS production flow to meet automotive reliability standards. All the parts are fully tested with respect to temperature to ensure the highest quality level.

The sensing elements are manufactured using ST’s proprietary micromachining processes, while the IC interfaces are developed using CMOS technology that allows the design of a dedicated circuit, which is trimmed to better match the characteristics of the sensing element.

The ASM330LHHX has a full-scale acceleration range of ±2/±4/±8/±16 g and a wide angular rate range of ±125/±250/±500/±1000/±2000/±4000 dps that enables its usage in a broad range of automotive applications.

The device supports dual operating modes: high-performance mode and low-power mode.

All the design aspects of the ASM330LHHX have been optimized to reach superior output stability, extremely low noise, and full data synchronization to the benefit of sensor-assisted applications like dead reckoning and sensor fusion.

The ASM330LHHX is available in a 14-lead plastic, land grid array (LGA) package.

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

§Installation

Add the driver to your Cargo.toml dependencies:

[dependencies]
asm330lhhx-rs = "1.0.0"

Or, add it directly from the terminal:

cargo add asm330lhhx-rs

§Usage

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

use asm330lhhx::asynchronous as asm330lhhx;
use asm330lhhx::*;
use asm330lhhx::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]
asm330lhhx-rs = { version = "1.0.0", default-features = false, features = ["blocking"] }

or from the terminal:

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

Then import the blocking API:

use asm330lhhx::blocking as asm330lhhx;
use asm330lhhx::*;
use asm330lhhx::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, along with a timing peripheral.

An example with I2C:

let mut sensor = Asm330lhhx::new_i2c(i2c, I2CAddress::I2cAddH, delay);

§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.device_id_get().unwrap();
if whoami != ID {
    panic!("Invalid sensor ID");
}

§Configure

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

// Restore default configuration
sensor.reset_set(PROPERTY_ENABLE).unwrap();

loop {
    let rst = sensor.reset_get().unwrap();
    if rst == 0 {
        break;
    }
}

// Start device configuration
sensor.device_conf_set(PROPERTY_ENABLE).unwrap();
// Enable Block Data Update
sensor.block_data_update_set(PROPERTY_ENABLE).unwrap();

// Set Output Data Rate
sensor.xl_data_rate_set(OdrXl::_12_5hz).unwrap();
sensor.gy_data_rate_set(OdrGy::_12_5hz).unwrap();
// Set Full Scale
sensor.xl_full_scale_set(FsXl::_2g).unwrap();
sensor.gy_full_scale_set(FsGy::_2000dps).unwrap();

§License

Distributed under the BSD-3 Clause license.

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

Copyright (C) 2026 STMicroelectronics

Modules§

asynchronous
blocking