How to use the HTS221 part API. It illustrates it by getting the values of the temperature (in celsius) and humidity (in %) and displaying them on a terminal.
Initialization phase: At main program start, the mx_system_init() function is called. It initializes the peripherals, nonvolatile memory (such as flash memory, NVM, or external memories), MPU regions (if applicable), the system clock, and the SysTick.
The application executes the following example steps:
Step 1: Initializes and enables temperature and humidity features of HTS221
Step 2: Gets the values of the temperature (in celsius) and the humidity (in %) and displays them on a terminal
End of example: It is an endless example that loops infinitely on step 2
You can follow these execution steps in the terminal logs:
[INFO] Step 1: HTS221 sensor init completed
[INFO] Step 1: Enabling TEMP and HUM features completed
[INFO] Step 2: TEMP 31 degC
[INFO] Step 2: HUM 46 %
[INFO] Step 2: TEMP 31 degC
[INFO] Step 2: HUM 46 %
This example demonstrates the following driver:
- Part hts221.c/.h
- Part hts221/interfaces/i2c/hts221_io.c/.h
In this example, the HTS221 component is configured through the I2C IO operations defined under the folder "interfaces/i2c." Once the I2C is initialized, the HTS221 can be initialized too through the call of hts221_drv_init() API. After this step, the MEMS sensor will be ready to provide the values of the temperature and humidity.
This section describes the hardware setup principles that apply to any board.
On STM32C5 series.
On board NUCLEO-C562RE.
| Board connector | MCU pin | Signal name | ARDUINO connector pin |
|---|---|---|---|
| CN5-10 | PB6 | I2C1_SCL | ARDUINO CONNECTOR - D15 |
| CN5-9 | PB7 | I2C1_SDA | ARDUINO CONNECTOR - D14 |
To create a functional project, complete the following steps:
- Select the appropriate IoC2 file based on the combination of NUCLEO and X-NUCLEO boards. For example, use c562re_iks01a3_hts221_datalog_i2c.ioc2 for NUCLEO-C562RE and X-NUCLEO-IKS01A3.
- Open the IoC2 file with STM32CubeMX2.
- Select the preferred toolchain and generate the source code.
- Copy the main.c, main.h, example.c, and example.h files into the project folder of the generated code.
- Open the Integrated Development Environment (IDE), add the example.c and example.h files to the project.
- Add the USE_TRACE=1 to the global variables of the project.
- Compile the project.
No specific debug tips.
More information about HTS221 part driver can be found in the HTS221 Part Driver
More information about the STM32 ecosystem can be found in the STM32 MCU Developer Zone.
Copyright (c) 2026 STMicroelectronics.
This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.