Skip to content

stm32-hotspot/stm32cubemx2_lis2duxs12_datalog_i2c

Repository files navigation

Example: lis2duxs12_datalog_i2c

How to use the LIS2DUXS12 part API.

It illustrates it by getting the values of the accelerometer (in mg) and displaying them on a terminal.

1. Detailed scenario

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 accelerometer feature of LIS2DUXS12

Step 2: Gets the values of the accelerometer (in mg) 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: LIS2DUXS12 sensor init completed
[INFO] Step 1: Enabling the ACC feature completed
[INFO] Step 2: ACC X=88 Y=-72 Z=1007

2. Example configuration

This example demonstrates the following driver:

  • Part lis2duxs12.c/.h
  • Part lis2duxs12/interfaces/i2c/lis2duxs12_io.c/.h

In this example, the LIS2DUXS12 component is configured through the I2C IO operations defined under the folder interfaces/i2c. Once the I2C is initialized, the LIS2DUXS12 can be initialized too through the call of lis2duxs12_drv_init() API. After this step, the MEMS sensor will be ready to provide the values of the accelerometer.

3. Hardware environment and setup

3.1. Generic Setup

This section describes the hardware setup principles that apply to any board.

3.2. Specific board setups

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
  • I2C ADDw = 0x33 (7-bit address).

4. Software setup

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_iks4a1_lis2duxs12_datalog_i2c.ioc2 for NUCLEO-C562RE and X-NUCLEO-IKS4A1.
  • 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.

5. Troubleshooting

No specific debug tips.

6. See Also

More information about LIS2DUXS12 part driver can be found in the LIS2DUXS12 Part Driver

More information about the STM32 ecosystem can be found in the STM32 MCU Developer Zone.

7. License

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.

About

Example of usage of ST components and middlewares with STM32CubeMX2

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages