Skip to content

Commit 47bf9ee

Browse files
dcpleungnashif
authored andcommitted
samples: sensors: add a new one for lsm6dso as I2C on I3C bus
This adds some skeleton files to enable using LSM6DSO on I3C bus while still acting like a I2C device. The new files here are simply to provide a way to have overlay for each board that would not conflict with the pure I2C one. Also this is set to build only because it require external hardware that is not necessary on the board being tested. Signed-off-by: Daniel Leung <[email protected]>
1 parent 34e353c commit 47bf9ee

File tree

6 files changed

+138
-0
lines changed

6 files changed

+138
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(lsm6dso_i2c_on_i3c)
6+
7+
FILE(GLOB app_sources ../lsm6dso/src/*.c)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
.. _lsm6dso_i2c_on_i3c:
2+
3+
LSM6DSO: IMU Sensor Monitor (I2C on I3C bus)
4+
############################################
5+
6+
Overview
7+
********
8+
This sample sets the date rate of LSM6DSO accelerometer and gyroscope to
9+
12.5Hz and enables a trigger on data ready. It displays on the console
10+
the values for accelerometer and gyroscope.
11+
12+
Requirements
13+
************
14+
15+
This sample uses the LSM6DSO sensor controlled using the I2C interface
16+
exposed by the I3C controller. It has been tested using the LSM6DSO on
17+
the evaluation board STEVAL-MKI196V1 connected to the I3C header
18+
on :ref:`mimxrt685_evk`.
19+
20+
References
21+
**********
22+
23+
- LSM6DSO http://www.st.com/en/mems-and-sensors/lsm6dso.html
24+
25+
Building and Running
26+
********************
27+
28+
This project outputs sensor data to the console. It requires an LSM6DSO
29+
sensor (for example, the one on evaluation board STEVAL-MKI196V1).
30+
31+
Building on mimxrt685_evk_cm33 board
32+
====================================
33+
34+
.. zephyr-app-commands::
35+
:zephyr-app: samples/sensor/lsm6dso_i2c_on_i3c
36+
:host-os: unix
37+
:board: mimxrt685_evk_cm33
38+
:goals: build
39+
:compact:
40+
41+
Board Preparations
42+
==================
43+
44+
mimxrt685_evk_cm33
45+
------------------
46+
47+
On the board :ref:`mimxrt685_evk`, the I3C pins are exposed on the J18
48+
header, where:
49+
50+
* SCL is on pin 1
51+
* SDA is on pin 2
52+
* Internal pull-up is on pin 3 (which is connected to pin 2 already)
53+
* Ground is on pin4
54+
55+
LSM6DSO
56+
^^^^^^^
57+
58+
A LSM6DSO sensor needs to be connected to this header. For example,
59+
the evaluation board STEVAL-MKI196V1 can be used. This needs to be
60+
prepared so that the LSM6DSO sensor has address 0x6B (i.e. 0xD6,
61+
left-shifed).
62+
63+
Sample Output
64+
=============
65+
66+
.. code-block:: console
67+
68+
Testing LSM6DSO sensor in trigger mode.
69+
70+
accel x:-0.650847 ms/2 y:-5.300102 ms/2 z:-8.163114 ms/2
71+
gyro x:-0.167835 dps y:-0.063377 dps z:0.002367 dps
72+
trig_cnt:1
73+
74+
accel x:0.341575 ms/2 y:5.209773 ms/2 z:-7.938787 ms/2
75+
gyro x:-0.034284 dps y:-0.004428 dps z:-0.003512 dps
76+
trig_cnt:2
77+
78+
<repeats endlessly>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Requires GPIO lines for interrupts,
2+
# so disable trigger mode and use polling mode for now.
3+
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=n
4+
CONFIG_LSM6DSO_TRIGGER_NONE=y
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
&i3c0 {
2+
status = "okay";
3+
4+
/*
5+
* There might be other connected I2C devices
6+
* (for example, if using Arduino shield) which
7+
* cannot tolerate high clock speed. So slow
8+
* down the clock.
9+
*/
10+
i2c-scl-hz = <400000>;
11+
i3c-scl-hz = <400000>;
12+
i3c-od-scl-hz = <400000>;
13+
14+
clk-divider = <12>;
15+
clk-divider-slow = <1>;
16+
clk-divider-tc = <1>;
17+
18+
lsm6dso0: lsm6dso@6b0000000000000050 {
19+
compatible = "st,lsm6dso";
20+
reg = <0x6b 0x00 0x50>;
21+
22+
status = "okay";
23+
};
24+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
CONFIG_CBPRINTF_FP_SUPPORT=y
3+
4+
CONFIG_I3C=y
5+
CONFIG_SENSOR=y
6+
7+
CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD=y
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
sample:
2+
name: LSM6DSO accelerometer and gyrometer sensor (I2C on I3C bus)
3+
tests:
4+
sample.sensor.lsm6dso.i2c_on_i3c_bus:
5+
harness: console
6+
tags: sensors
7+
depends_on: i3c
8+
filter: dt_compat_enabled("st,lsm6dso")
9+
timeout: 15
10+
build_only: true
11+
harness_config:
12+
type: multi_line
13+
ordered: true
14+
regex:
15+
- "accel x:[-.0-9]* ms/2 y:[-.0-9]* ms/2 z:[-.0-9]* ms/2"
16+
- "gyro x:[-.0-9]* dps y:[-.0-9]* dps z:[-.0-9]* dps"
17+
- "trig_cnt:[0-9]*"

0 commit comments

Comments
 (0)