<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/121174/trigger-mode-on-lsm6dso</link><description>Hello, 
 I&amp;#39;ve been working on a project involving an IMU and bluetooth for a while, and had been using the IMU (LSM6DSO) on polling mode. Unfortunately, I found out that I will need to use trigger mode for this application, so I&amp;#39;ve been trying to figure</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 26 May 2025 16:21:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/121174/trigger-mode-on-lsm6dso" /><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/537002?ContentTypeID=1</link><pubDate>Mon, 26 May 2025 16:21:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df73f4bc-be63-4b1e-b458-f90b0101ddc0</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;Final update is that seems to be working for the most part with the exception of some glitches where the IMU doesn&amp;#39;t initialize upon powerup occasionally. My questions have transitioned from the IMU and trigger mode to lower power stuff, so I made a new post that summarizes where I&amp;#39;m at, which can be found &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/121771/low-power-mode-on-nrf52832-with-lsm6dso-trigger-based-wakeup-and-bluetooth"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/535866?ContentTypeID=1</link><pubDate>Sat, 17 May 2025 21:11:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a667d8ec-d2c2-4768-910d-25ffe5a7635b</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;Okay, new update. Things are working better now. I went through a lot of work changing the register values to get to a configuration that would work. I switched to INT2 but it was constantly being held low, so I ended up going back to INT1 and it is functional now. My callback function in my main code does work, and triggers corresponding to a small tap on the IMU (which is close enough to my desired behavior).&lt;/p&gt;
&lt;p&gt;The current issue that I am having is that the triggering doesn&amp;#39;t always work on the NRF side. What I mean by this is that my logic analyzer shows a pulse in int1, but my callback function doesn&amp;#39;t work. I would say that it works most of the time, but it is odd that it isn&amp;#39;t fully consistent. Additionally, when this function gets called, it sometimes turns on LED 3 and 4, which I believe indicates a fault of some sort. I am still able to trigger this function again afterwards, but it required a larger acceleration magnitude (I have no clue why). Some insight into why the LEDs are turning on would be helpful if that is something anyone knows about.&lt;/p&gt;
&lt;p&gt;My next step is to implement the nrf low power mode, and use this interrupt signal to turn on the chip fully and send data over bluetooth, before putting it to sleep again and reenabling trigger mode. I&amp;#39;ll likely work on this early next week, but in the meantime if anyone can help explain the LED behavior it would be appreciated. Thank you for the help! I will share my current code below so you can reference it.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2020 Yestin Sun
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/sensor.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2c.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

#define INT1_NODE DT_ALIAS(lsm6dso_int1)

#if DT_NODE_HAS_STATUS(INT1_NODE, okay)
static const struct gpio_dt_spec int1_gpio = GPIO_DT_SPEC_GET(INT1_NODE, irq_gpios);
#else
#error &amp;quot;INT1_NODE is not defined or not okay in the device tree&amp;quot;
#endif
static struct gpio_callback int1_cb_data;


// Replace with correct label from your board&amp;#39;s devicetree if needed
#define I2C_BUS DT_NODELABEL(i2c0)
#define LSM6DSO_I2C_ADDR 0x6B 

static const struct device *i2c_dev = DEVICE_DT_GET(I2C_BUS);

static int lsm6dso_write_reg(uint8_t reg, uint8_t val) {
	return i2c_reg_write_byte(i2c_dev, LSM6DSO_I2C_ADDR, reg, val);
}

static int lsm6dso_read_reg(uint8_t reg, uint8_t *val) {
	return i2c_reg_read_byte(i2c_dev, LSM6DSO_I2C_ADDR, reg, val);
}



static inline float out_ev(struct sensor_value *val)
{
	return (val-&amp;gt;val1 + (float)val-&amp;gt;val2 / 1000000);
}

static void fetch_and_display(const struct device *dev)
{
	struct sensor_value x, y, z;
	static int trig_cnt;

	trig_cnt++;

	/* lsm6dso accel */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &amp;amp;z);

	printf(&amp;quot;accel x:%f ms/2 y:%f ms/2 z:%f ms/2\n&amp;quot;,
			(double)out_ev(&amp;amp;x), (double)out_ev(&amp;amp;y), (double)out_ev(&amp;amp;z));

	/* lsm6dso gyro */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &amp;amp;z);

	printf(&amp;quot;gyro x:%f rad/s y:%f rad/s z:%f rad/s\n&amp;quot;,
			(double)out_ev(&amp;amp;x), (double)out_ev(&amp;amp;y), (double)out_ev(&amp;amp;z));

	printf(&amp;quot;trig_cnt:%d\n\n&amp;quot;, trig_cnt);
}

static int set_sampling_freq(const struct device *dev)
{
	int ret = 0;
	struct sensor_value odr_attr;

	/* set accel/gyro sampling frequency to 12.5 Hz */
	odr_attr.val1 = 12.5;
	odr_attr.val2 = 0;

	ret = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for accelerometer.\n&amp;quot;);
		return ret;
	}

	ret = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for gyro.\n&amp;quot;);
		return ret;
	}

	return 0;
}

static struct k_work lsm6dso_work;

// This function is safe to run outside ISR context
static void lsm6dso_work_handler(struct k_work *work)
{
	gpio_pin_interrupt_configure_dt(&amp;amp;int1_gpio, GPIO_INT_DISABLE);
    // const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso);
    // if (!device_is_ready(dev)) {
    //     printk(&amp;quot;LSM6DSO device not ready\n&amp;quot;);
    //     return;
    // }
	uint8_t wake_src, tap_src, status;
	lsm6dso_read_reg(0x1B, &amp;amp;wake_src);
	lsm6dso_read_reg(0x1C, &amp;amp;tap_src);
	lsm6dso_read_reg(0x1E, &amp;amp;status);
    printk(&amp;quot;Wake-up SRC: 0x%02X\n&amp;quot;, wake_src);
    printk(&amp;quot;callback triggered.\n&amp;quot;);

    //fetch_and_display(dev);  // Whatever your normal logic is
	k_sleep(K_MSEC(1000));  
	gpio_pin_interrupt_configure_dt(&amp;amp;int1_gpio, GPIO_INT_EDGE_TO_ACTIVE);
}

static void lsm6dso_int1_callback(const struct device *port, struct gpio_callback *cb, uint32_t pins)
{
	k_work_submit(&amp;amp;lsm6dso_work);
}

static void setup_int1_gpio(void)
{
    //gpio_pin_configure_dt(&amp;amp;int1_gpio, GPIO_INPUT);
	gpio_pin_configure_dt(&amp;amp;int1_gpio, GPIO_INPUT | GPIO_PULL_UP);
    gpio_pin_interrupt_configure_dt(&amp;amp;int1_gpio, GPIO_INT_EDGE_TO_ACTIVE);
    gpio_init_callback(&amp;amp;int1_cb_data, lsm6dso_int1_callback, BIT(int1_gpio.pin));
    gpio_add_callback(int1_gpio.port, &amp;amp;int1_cb_data);
}

static void reset_registers(void){
	// 1. Reset device (optional but good practice)
	lsm6dso_write_reg(0x12, 0x01);  // CTRL3_C: SW_RESET
	k_sleep(K_MSEC(100));            // Delay to allow reset

	// 2. Disable all interrupts on INT1 and INT2
	lsm6dso_write_reg(0x5E, 0x00);  // MD1_CFG: no interrupt routed
	lsm6dso_write_reg(0x5F, 0x00);  // MD2_CFG: no interrupt routed

	// 3. Disable embedded functions, just basic accelerometer on 104 Hz, &amp;#177;2g
	lsm6dso_write_reg(0x10, 0x40);  // CTRL1_XL: 104 Hz, &amp;#177;2g
	lsm6dso_write_reg(0x11, 0x00);  // CTRL2_G: gyroscope off
	lsm6dso_write_reg(0x12, 0x44);  // CTRL3_C: BDU + auto-increment enabled

	// 4. Disable embedded functions access
	lsm6dso_write_reg(0x19, 0x00);  // FUNC_CFG_ACCESS: disable

	// 5. Read INT1 pin voltage level with logic analyzer or voltmeter

}

// Function to read 6 bytes of accelerometer data (X, Y, Z)
void read_accel_data(void) {
    uint8_t accel_xl[6];  // Buffer to store 6 bytes of accelerometer data
    int ret;

    // Read 6 consecutive bytes starting from register 0x28
    for (int i = 0; i &amp;lt; 6; i++) {
        ret = lsm6dso_read_reg(0x28 + i, &amp;amp;accel_xl[i]);
        if (ret != 0) {
            printk(&amp;quot;Failed to read register 0x%02X\n&amp;quot;, 0x28 + i);
            return;
        }
    }

    // Convert the raw data to meaningful values
    int16_t accel_x = (int16_t)((accel_xl[1] &amp;lt;&amp;lt; 8) | accel_xl[0]);  // X-axis
    int16_t accel_y = (int16_t)((accel_xl[3] &amp;lt;&amp;lt; 8) | accel_xl[2]);  // Y-axis
    int16_t accel_z = (int16_t)((accel_xl[5] &amp;lt;&amp;lt; 8) | accel_xl[4]);  // Z-axis

    // Print the raw accelerometer values
    printk(&amp;quot;Accel X: %d, Y: %d, Z: %d\n&amp;quot;, accel_x, accel_y, accel_z);
}

static void read_all_registers(void)
{
	uint8_t reg;
	lsm6dso_read_reg(0x1A, &amp;amp;reg); printk(&amp;quot;ALL_INT_SRC: 0x%02X\n&amp;quot;, reg);
	lsm6dso_read_reg(0x1B, &amp;amp;reg); printk(&amp;quot;WAKE_UP_SRC: 0x%02X\n&amp;quot;, reg);
	lsm6dso_read_reg(0x1C, &amp;amp;reg); printk(&amp;quot;TAP_SRC: 0x%02X\n&amp;quot;, reg);
	lsm6dso_read_reg(0x1D, &amp;amp;reg); printk(&amp;quot;D6D_SRC: 0x%02X\n&amp;quot;, reg);
	lsm6dso_read_reg(0x53, &amp;amp;reg); printk(&amp;quot;FUNC_SRC1: 0x%02X\n&amp;quot;, reg);
	lsm6dso_read_reg(0x54, &amp;amp;reg); printk(&amp;quot;FUNC_SRC2: 0x%02X\n&amp;quot;, reg);
	lsm6dso_read_reg(0x12, &amp;amp;reg); printk(&amp;quot;CTRL3_C: 0x%02X\n&amp;quot;, reg);
	lsm6dso_read_reg(0x5E, &amp;amp;reg); printk(&amp;quot;MD1_CFG: 0x%02X\n&amp;quot;, reg);
}

static void lsm6dso_config_motion_interrupt(void)
{
	reset_registers();
	// 1. Enable BDU and auto-increment
	lsm6dso_write_reg(0x12, 0x44);  // CTRL3_C

	// 2. Enable accelerometer: ODR = 104 Hz, FS = &amp;#177;4g
	lsm6dso_write_reg(0x10, 0x50);  // CTRL1_XL

	// 3. Enable access to embedded functions
	lsm6dso_write_reg(0x01A, 0x80); // FUNC_CFG_ACCESS = enable embedded reg access

	// 4. Enable embedded functions
	lsm6dso_write_reg(0x04, 0x01);  // EMB_FUNC_EN_A = enable wake-up
	lsm6dso_write_reg(0x05, 0x00);  // EMB_FUNC_EN_B = (optional)

	// 5. Enable embedded function interrupt
	lsm6dso_write_reg(0x58, 0x80);  // TAP_CFG0: enable interrupts
	lsm6dso_write_reg(0x59, 0x0C);  // TAP_CFG2: route wake-up to INTs

	// 6. Set wake-up threshold and duration
	lsm6dso_write_reg(0x5B, 0x02);  // WAKE_UP_THS = ~2g
	lsm6dso_write_reg(0x5C, 0x00);  // WAKE_UP_DUR = min duration

	// 7. Route wake-up interrupt to INT2
	lsm6dso_write_reg(0x5F, 0x20);  // MD2_CFG: bit 5 = wake-up INT2
	// 7b. Route core wake-up interrupt to INT2 (not just embedded wake-up)
	//lsm6dso_write_reg(0x5E, 0x20);
	//lsm6dso_write_reg(0x0F, 0x20);  // INT2_CTRL: Wake-up to INT2


	// 8. (Optional) Enable HPF for reliable wake-up
	lsm6dso_write_reg(0x17, 0x09);  // CTRL8_XL: no HPF

	// 9. Exit embedded access mode
	lsm6dso_write_reg(0x1A, 0x00);  // FUNC_CFG_ACCESS = user bank

	// 10. Enable Wake-Up in CTRL10_C
	lsm6dso_write_reg(0x19, 0x24);  // CTRL10_C: FUNC_EN | WAKE_EN

	// 11. Configure INT2: push-pull, active high
	lsm6dso_write_reg(0x13, 0x00);  // CTRL4_C: default push-pull

	// 12. Enable interrupt latch
	lsm6dso_write_reg(0x0B, 0x40);  // CTRL6_C: LIR = 1

	// Explicitly disable wake-up on INT1
	lsm6dso_write_reg(0x5E, 0x00);  // MD1_CFG: clear wake-up routing on INT1

	// Route wake-up interrupt to INT2
	lsm6dso_write_reg(0x5F, 0x20);  // MD2_CFG: wake-up INT2

	// Explicitly route wake-up interrupt on INT2 control register
	lsm6dso_write_reg(0x0F, 0x20);  // INT2_CTRL: wake-up interrupt to INT2

	// Disable wake-up on INT1 control register
	lsm6dso_write_reg(0x0E, 0x00);  // INT1_CTRL

	// Optional: configure INT2 pin type
	lsm6dso_write_reg(0x13, 0x00);  // or try 0x02 for open-drain

	//enable int1 code below
	// Disable INT2
	lsm6dso_write_reg(0x5F, 0x00);  // MD2_CFG
	lsm6dso_write_reg(0x0F, 0x00);  // INT2_CTRL

	// Enable INT1 for wake-up
	lsm6dso_write_reg(0x5E, 0x20);  // MD1_CFG: route wake-up to INT1
	lsm6dso_write_reg(0x0E, 0x20);  // INT1_CTRL: route core wake-up to INT1

}


static void test_trigger_mode(const struct device *dev)
{
	if (set_sampling_freq(dev) != 0) {
		return;
	}

	lsm6dso_config_motion_interrupt();  // &amp;lt;--- manually configure 2g motion INT
	k_msleep(100); 
	setup_int1_gpio();


	//reset_registers();

	while (1) {
        
    }	
   
}



int main(void)
{
	const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso);

	if (!device_is_ready(dev)) {
		printk(&amp;quot;%s: device not ready.\n&amp;quot;, dev-&amp;gt;name);
		return 0;
	}

	k_work_init(&amp;amp;lsm6dso_work, lsm6dso_work_handler);


	printf(&amp;quot;Testing LSM6DSO sensor in trigger mode.\n\n&amp;quot;);
	test_trigger_mode(dev);
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/535201?ContentTypeID=1</link><pubDate>Tue, 13 May 2025 20:04:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c1d13c5a-0a0b-4323-9ff7-84043c8be7da</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;I&amp;#39;ve been testing it more, and I&amp;#39;m starting to think that the triggering may not be based directly on the interrupt signal and the acceleration values that the LSM6DSO records. When I manually unplug and plug in gpio 12 (which I am using as my INT1 pin), it triggers the value. I think that this behavior matches what I was seeing before, and makes me think that may be why I&amp;#39;m getting odd behavior and inconsistent triggering. It may have been that the reason it required a very aggressive shake to trigger before was that the shaking was physically disconnecting and reconnecting the wire, or something similar. I&amp;#39;m pretty stumped still and am not sure what to look into next.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/534750?ContentTypeID=1</link><pubDate>Sat, 10 May 2025 20:33:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40589761-d6cd-4da5-a593-17279010c765</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;Okay, I&amp;#39;ve been putting a lot of time into this and have made some progress, which I will share here. My code compiles and runs, and I have been able to get trigger mode working (somewhat) without using the trigger modes in the drivers. I manually change register values and have a different interrupt handler function that does successfully trigger. Now, I&amp;#39;m running into a bunch of odd behavior that I could use help figuring out.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1. Register values don&amp;#39;t seem to correspond to trigger sensitivity. For instance, I&amp;#39;ve been trying to lower the trigger threshold register value in my code (from 4g to 2g, or 2g to 1g) and if anything that makes it harder to trigger. Also, the wake up duration being set to 0 makes it so I can&amp;#39;t trigger it at all (I have no clue why this would be the case, if anything this should make triggering more sensitive/frequent.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. I print the state of my gpio pin after the interrupt. Sometimes it is 0 (which it should be since its cleared), but other times it is 1. I have no clue why, it seems random.&lt;/p&gt;
&lt;p&gt;3. Occasionally, LED 3 and 4 on on my DK both turn on. This is not something that I do in my code at all, and I have no clue why this happens.&lt;/p&gt;
&lt;p&gt;4. After triggering, sometimes it does not let me trigger again. This seems to correspond to either the behavior I mentioned in (2) or (3) occurring.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll share my current code, devicetree overlay, config file, and some sample output. Any advice would be appreciated!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2020 Yestin Sun
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/sensor.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2c.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;

#define INT1_NODE DT_ALIAS(lsm6dso_int1)

#if DT_NODE_HAS_STATUS(INT1_NODE, okay)
static const struct gpio_dt_spec int1_gpio = GPIO_DT_SPEC_GET(INT1_NODE, irq_gpios);
#else
#error &amp;quot;INT1_NODE is not defined or not okay in the device tree&amp;quot;
#endif
static struct gpio_callback int1_cb_data;


// Replace with correct label from your board&amp;#39;s devicetree if needed
#define I2C_BUS DT_NODELABEL(i2c0)
#define LSM6DSO_I2C_ADDR 0x6B 

static const struct device *i2c_dev = DEVICE_DT_GET(I2C_BUS);

static int lsm6dso_write_reg(uint8_t reg, uint8_t val) {
	return i2c_reg_write_byte(i2c_dev, LSM6DSO_I2C_ADDR, reg, val);
}

static int lsm6dso_read_reg(uint8_t reg, uint8_t *val) {
	return i2c_reg_read_byte(i2c_dev, LSM6DSO_I2C_ADDR, reg, val);
}



static inline float out_ev(struct sensor_value *val)
{
	return (val-&amp;gt;val1 + (float)val-&amp;gt;val2 / 1000000);
}

static void fetch_and_display(const struct device *dev)
{
	struct sensor_value x, y, z;
	static int trig_cnt;

	trig_cnt++;

	/* lsm6dso accel */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &amp;amp;z);

	printf(&amp;quot;accel x:%f ms/2 y:%f ms/2 z:%f ms/2\n&amp;quot;,
			(double)out_ev(&amp;amp;x), (double)out_ev(&amp;amp;y), (double)out_ev(&amp;amp;z));

	/* lsm6dso gyro */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &amp;amp;z);

	printf(&amp;quot;gyro x:%f rad/s y:%f rad/s z:%f rad/s\n&amp;quot;,
			(double)out_ev(&amp;amp;x), (double)out_ev(&amp;amp;y), (double)out_ev(&amp;amp;z));

	printf(&amp;quot;trig_cnt:%d\n\n&amp;quot;, trig_cnt);
}

static int set_sampling_freq(const struct device *dev)
{
	int ret = 0;
	struct sensor_value odr_attr;

	/* set accel/gyro sampling frequency to 12.5 Hz */
	odr_attr.val1 = 12.5;
	odr_attr.val2 = 0;

	ret = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for accelerometer.\n&amp;quot;);
		return ret;
	}

	ret = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for gyro.\n&amp;quot;);
		return ret;
	}

	return 0;
}

static struct k_work lsm6dso_work;

// This function is safe to run outside ISR context
static void lsm6dso_work_handler(struct k_work *work)
{
    const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso);
    if (!device_is_ready(dev)) {
        printk(&amp;quot;LSM6DSO device not ready\n&amp;quot;);
        return;
    }

    uint8_t wake_src;
    lsm6dso_read_reg(0x1B, &amp;amp;wake_src);  // Safe here
    printk(&amp;quot;Wake-up SRC: 0x%02X\n&amp;quot;, wake_src);
    printk(&amp;quot;callback triggered.\n&amp;quot;);

    fetch_and_display(dev);  // Whatever your normal logic is
}

static void lsm6dso_int1_callback(const struct device *port, struct gpio_callback *cb, uint32_t pins)
{
	
	uint8_t wake_src;
    lsm6dso_read_reg(0x1B, &amp;amp;wake_src);  // Read to clear the interrupt flag
    printk(&amp;quot;Wake-up SRC: 0x%02X\n&amp;quot;, wake_src);  // Optional: debug info
	// printk(&amp;quot;callback triggered.\n&amp;quot;); 
	//k_sleep(K_MSEC(500));
    // const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso);
    // fetch_and_display(dev);  // Or whatever handler logic you want
	k_work_submit(&amp;amp;lsm6dso_work);
	int gpio_state = gpio_pin_get(port, 12);  
    printk(&amp;quot;GPIO pin state after interrupt: %d\n&amp;quot;, gpio_state);  // Should print 0 (low) if cleared properly
	
}

static void setup_int1_gpio(void)
{
    //gpio_pin_configure_dt(&amp;amp;int1_gpio, GPIO_INPUT);
	gpio_pin_configure_dt(&amp;amp;int1_gpio, GPIO_INPUT | GPIO_PULL_UP);
    gpio_pin_interrupt_configure_dt(&amp;amp;int1_gpio, GPIO_INT_EDGE_TO_ACTIVE);
    gpio_init_callback(&amp;amp;int1_cb_data, lsm6dso_int1_callback, BIT(int1_gpio.pin));
    gpio_add_callback(int1_gpio.port, &amp;amp;int1_cb_data);
}

#ifdef CONFIG_LSM6DSO_TRIGGER
static void trigger_handler(const struct device *dev,
			    const struct sensor_trigger *trig)
{
	fetch_and_display(dev);
}

// Function to read 6 bytes of accelerometer data (X, Y, Z)
void read_accel_data(void) {
    uint8_t accel_xl[6];  // Buffer to store 6 bytes of accelerometer data
    int ret;

    // Read 6 consecutive bytes starting from register 0x28
    for (int i = 0; i &amp;lt; 6; i++) {
        ret = lsm6dso_read_reg(0x28 + i, &amp;amp;accel_xl[i]);
        if (ret != 0) {
            printk(&amp;quot;Failed to read register 0x%02X\n&amp;quot;, 0x28 + i);
            return;
        }
    }

    // Convert the raw data to meaningful values
    int16_t accel_x = (int16_t)((accel_xl[1] &amp;lt;&amp;lt; 8) | accel_xl[0]);  // X-axis
    int16_t accel_y = (int16_t)((accel_xl[3] &amp;lt;&amp;lt; 8) | accel_xl[2]);  // Y-axis
    int16_t accel_z = (int16_t)((accel_xl[5] &amp;lt;&amp;lt; 8) | accel_xl[4]);  // Z-axis

    // Print the raw accelerometer values
    printk(&amp;quot;Accel X: %d, Y: %d, Z: %d\n&amp;quot;, accel_x, accel_y, accel_z);
}


static void lsm6dso_config_motion_interrupt(void)
{
	// 1. Enable BDU and auto-increment
	lsm6dso_write_reg(0x12, 0x44);  // CTRL3_C

	// 2. Enable accelerometer: ODR = 104 Hz, FS = &amp;#177;4g (0x50)
	lsm6dso_write_reg(0x10, 0x50);  // CTRL1_XL

	lsm6dso_write_reg(0x19, 0x01);  // FUNC_CFG_ACCESS = 1 → Enable embedded register access

	lsm6dso_write_reg(0x04, 0x01);  // EMB_FUNC_EN_A: Enable embedded functions

	// 3. Enable embedded function interrupt
	lsm6dso_write_reg(0x58, 0x80);  // TAP_CFG0: INT_EN = 1

	// 4. Set wake-up threshold to 2g → 0x10 (FS=4g, 0.125g/LSB)
	lsm6dso_write_reg(0x5B, 0x20);  // WAKE_UP_THS

	// 5. Set no additional duration for interrupt
	lsm6dso_write_reg(0x5C, 0x01);  // WAKE_UP_DUR

	// 6. Route wake-up interrupt to INT1
	lsm6dso_write_reg(0x5E, 0x20);  // MD1_CFG: Wake-up INT on INT1

	printk(&amp;quot;LSM6DSO motion interrupt configured for 2g threshold.\n&amp;quot;);
}

static void test_trigger_mode(const struct device *dev)
{
	if (set_sampling_freq(dev) != 0) {
		return;
	}

	lsm6dso_config_motion_interrupt();  // &amp;lt;--- manually configure 2g motion INT
	k_msleep(100); 
	setup_int1_gpio();
	// struct sensor_trigger trig;
	// trig.type = SENSOR_TRIG_DELTA;  // Could be SENSOR_TRIG_DATA_READY, both should work
	// trig.chan = SENSOR_CHAN_ACCEL_XYZ;

	// if (sensor_trigger_set(dev, &amp;amp;trig, trigger_handler) != 0) {
	// 	printf(&amp;quot;Could not set sensor trigger.\n&amp;quot;);
	// 	return;
	// }
	uint8_t wake_src;
	for (;;){
		// lsm6dso_read_reg(0x1B, &amp;amp;wake_src);  // Clear the interrupt
    	// printk(&amp;quot;Wake-up SRC: 0x%02X\n&amp;quot;, wake_src);  // Optional: debug info
		// read_accel_data();
		// k_sleep(K_MSEC(3000));
	}
   
}


#else
static void test_polling_mode(const struct device *dev)
{
	if (set_sampling_freq(dev) != 0) {
		return;
	}

	while (1) {
		fetch_and_display(dev);
		k_sleep(K_MSEC(1000));
	}
}
#endif


int main(void)
{
	const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso);

	if (!device_is_ready(dev)) {
		printk(&amp;quot;%s: device not ready.\n&amp;quot;, dev-&amp;gt;name);
		return 0;
	}

	k_work_init(&amp;amp;lsm6dso_work, lsm6dso_work_handler);


#ifdef CONFIG_LSM6DSO_TRIGGER
	printf(&amp;quot;Testing LSM6DSO sensor in trigger mode.\n\n&amp;quot;);
	test_trigger_mode(dev);
#else
	printf(&amp;quot;Testing LSM6DSO sensor in polling mode.\n\n&amp;quot;);
	test_polling_mode(dev);
#endif
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Devicetree overlay:&amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;i2c0&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;lsm6dso:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;lsm6dso&lt;/span&gt;&lt;span&gt;@&lt;/span&gt;&lt;span&gt;6b&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;compatible&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;quot;st,lsm6dso&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;reg&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &amp;lt;&lt;/span&gt;&lt;span&gt;0x6b&lt;/span&gt;&lt;span&gt;&amp;gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;label&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;quot;LSM6DSO&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;irq-gpios&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &amp;lt;&lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;gpio0&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;12&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;GPIO_ACTIVE_HIGH&lt;/span&gt;&lt;span&gt;&amp;gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;int-pin&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &amp;lt;&lt;/span&gt;&lt;span&gt;1&lt;/span&gt;&lt;span&gt;&amp;gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;status&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;quot;okay&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; };&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;{/aliases}&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;lsm6dso-int1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;lsm6dso&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Config file:&amp;nbsp;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_STDOUT_CONSOLE&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_I2C&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_GPIO&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_SENSOR&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_LSM6DSO&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;span&gt;CONFIG_LSM6DSO_TRIGGER_GLOBAL_THREAD&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_CBPRINTF_FP_SUPPORT&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Sample Output:&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;Testing LSM6DSO sensor in trigger mode.&lt;br /&gt;&lt;br /&gt;LSM6DSO motion interrupt configured for 2g threshold.&lt;br /&gt;Wake-up SRC: 0x00&lt;br /&gt;GPIO pin state after interrupt: 0&lt;br /&gt;Wake-up SRC: 0x10&lt;br /&gt;callback triggered.&lt;br /&gt;accel x:-3.107080 ms/2 y:2.021935 ms/2 z:10.009775 ms/2&lt;br /&gt;gyro x:-0.037110 rad/s y:-0.007788 rad/s z:3.345860 rad/s&lt;br /&gt;trig_cnt:1&lt;br /&gt;&lt;br /&gt;Wake-up SRC: 0x00&lt;br /&gt;GPIO pin state after interrupt: 1&lt;br /&gt;Wake-up SRC: 0x00&lt;br /&gt;callback triggered.&lt;br /&gt;accel x:-18.340984 ms/2 y:0.000000 ms/2 z:0.629312 ms/2&lt;br /&gt;gyro x:-4.682281 rad/s y:0.000000 rad/s z:0.162490 rad/s&lt;br /&gt;trig_cnt:2&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/534164?ContentTypeID=1</link><pubDate>Tue, 06 May 2025 18:01:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f963fa7-f462-4b28-8ee3-186d127a713e</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;I believe the sensor itself should support this mode, but when I looked through the&amp;nbsp;lsm6dso.c trigger driver file and it appears that the only supported trigger mode is data ready, no threshold based interrupts. Unless I&amp;#39;m reading that wrong, I&amp;#39;ll need to configure the registers manually. I&amp;#39;ve been having some issues with that but will give it some more attempts and can share my code/outputs when I&amp;#39;ve done so.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/534017?ContentTypeID=1</link><pubDate>Tue, 06 May 2025 06:00:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d32994b-22b8-43b4-80a7-919738ff2f74</guid><dc:creator>runsiv</dc:creator><description>[quote user="connorshannon"]I kept getting issues with setting the trigger type to threshold and read somewhere that it might not be supported on the version I&amp;#39;m working with. [/quote]
&lt;p&gt;Not supported by the SW or the sensor itself?&amp;nbsp;&lt;/p&gt;
[quote user="connorshannon"]threshold.val1 and threshold.val2[/quote]
&lt;p&gt;That is not easy, the datasheet from ST seems to use binary so I would start there at least. It could also be an idea to see if they have any application note for for the sensor&amp;nbsp;&lt;/p&gt;
[quote user="connorshannon"] I&amp;#39;ve tried manually updating registers with code like this:[/quote]
&lt;p&gt;Configuring the registers manually is an option. However I suspect the driver to support it. Anyway worst case i would still use the sensor api to setup everything expect the threshold value. From what I can see the drivers is using the sensor api which has the properties&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;enum sensor_attribute {
	/**
	 * Sensor sampling frequency, i.e. how many times a second the
	 * sensor takes a measurement.
	 */
	SENSOR_ATTR_SAMPLING_FREQUENCY,
	/** Lower threshold for trigger. */
	SENSOR_ATTR_LOWER_THRESH,
	/** Upper threshold for trigger. */
	SENSOR_ATTR_UPPER_THRESH,
	/** Threshold for any-motion (slope) trigger. */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Which you can set like you did here&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	ret = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Runar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/533982?ContentTypeID=1</link><pubDate>Mon, 05 May 2025 17:57:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc24b42d-9f5f-44ce-b0bd-390f4a0e7bfd</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;It seems like there are two ways of handling triggering with this device: Manually configuring registers, or using the lsm6dso driver to enable it. Based on what I can find, threshold mode isn&amp;#39;t supported by the driver, so I will need to change the registers manually. The issue is that my trigger handler function no longer gets called if I don&amp;#39;t enable triggering mode via the drivers, so I would need to make a new function that gets called when the interrupt pin is triggered, but I have no clue how to do that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/533972?ContentTypeID=1</link><pubDate>Mon, 05 May 2025 16:36:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb33d172-514b-4a70-a26b-246cc32d7c55</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;I kept getting issues with setting the trigger type to threshold and read somewhere that it might not be supported on the version I&amp;#39;m working with. I also cannot find documentation as to what units the threshold.val1 and threshold.val2 are, so I&amp;#39;m not sure what values I actually set in the code you referenced. I&amp;#39;ve tried manually updating registers with code like this:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;// CTRL1_XL: Set accelerometer to 12.5 Hz, &amp;plusmn;4g&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;lsm6dso_write_reg&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;0x10&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0x50&lt;/span&gt;&lt;span&gt;); &amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;// WAKE_UP_THS: Set threshold ~2g (32 * 4g / 64 = 2g)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;lsm6dso_write_reg&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;0x5B&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0x20&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;// WAKE_UP_DUR: No delay&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;lsm6dso_write_reg&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;0x5C&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0x00&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;// MD1_CFG: Route wake-up to INT1&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;lsm6dso_write_reg&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;0x5E&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0x20&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;// CTRL3_C: Enable auto-increment&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;lsm6dso_write_reg&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;0x12&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span&gt;0x44&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;and no matter what I try, it still continuously triggers when it shouldn&amp;#39;t be. The code you shared was from an older version of what I was trying, but if you think that might be the right way to go about doing what I need to do, I can go back and check. I recall that for a while I was getting the output &amp;#39;failed to set acceleration threshold&amp;#39; and then nothing else.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/533902?ContentTypeID=1</link><pubDate>Mon, 05 May 2025 12:16:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:714b145d-4437-4712-8a06-7c446b5b657e</guid><dc:creator>runsiv</dc:creator><description>&lt;p&gt;Hi I will look into it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;From a first glance it looks like you are missing the second interrupt pin from the sensor.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;From the last update I can&amp;#39;t see that you put any threshold on the trigger at all.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When you used&amp;nbsp;&lt;/p&gt;
&lt;p&gt;// Set 2g threshold (approx. 19.6 m/s²)&lt;br /&gt; threshold.val1 = 19;&lt;br /&gt; threshold.val2 = 600000;&lt;/p&gt;
&lt;p&gt;if (sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SLOPE_TH, &amp;amp;threshold) != 0) {&lt;/p&gt;
&lt;p&gt;printf(&amp;quot;Failed to set acceleration threshold\n&amp;quot;);&lt;br /&gt; return;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;What did it return?&amp;nbsp; Did you try to read the config back?&lt;/p&gt;
&lt;p&gt;Regurn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trigger mode on LSM6DSO</title><link>https://devzone.nordicsemi.com/thread/533829?ContentTypeID=1</link><pubDate>Sun, 04 May 2025 22:09:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff6b1957-540a-49e6-806d-031ffb9b56e6</guid><dc:creator>connorshannon</dc:creator><description>&lt;p&gt;Hello, just spent another few hours on this and made some progress but am still struggling. The device gets trigger mode to work, but my current issue is that it is CONSTANTLY triggering no matter what I try to do to fix it. Overall, I&amp;#39;ve just been really struggling to find documentation regarding how this all works. I understand that another approach to this is to manually change the register values in the lsm6dso, and I tried that too but it didn&amp;#39;t work. All I really need is to setup the device so that it sends an interrupt/trigger when acceleration exceeds 2g. I&amp;#39;ll share my current code with the changes that I made so that it reads data from the sensor constantly. I don&amp;#39;t believe I made any changes to the devicetree overlay or config file.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2020 Yestin Sun
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/drivers/sensor.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/i2c.h&amp;gt;

static inline float out_ev(struct sensor_value *val)
{
	return (val-&amp;gt;val1 + (float)val-&amp;gt;val2 / 1000000);
}
#define LED0_NODE DT_ALIAS(led0)

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

static void fetch_and_display(const struct device *dev)
{
	struct sensor_value x, y, z;
	static int trig_cnt;

	trig_cnt++;

	/* lsm6dso accel */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &amp;amp;z);

	printf(&amp;quot;accel x:%f ms/2 y:%f ms/2 z:%f ms/2\n&amp;quot;,
			(double)out_ev(&amp;amp;x), (double)out_ev(&amp;amp;y), (double)out_ev(&amp;amp;z));

	/* lsm6dso gyro */
	sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &amp;amp;x);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &amp;amp;y);
	sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &amp;amp;z);

	printf(&amp;quot;gyro x:%f rad/s y:%f rad/s z:%f rad/s\n&amp;quot;,
			(double)out_ev(&amp;amp;x), (double)out_ev(&amp;amp;y), (double)out_ev(&amp;amp;z));

	printf(&amp;quot;trig_cnt:%d\n\n&amp;quot;, trig_cnt);
}

static int set_sampling_freq(const struct device *dev)
{
	int ret = 0;
	struct sensor_value odr_attr;

	/* set accel/gyro sampling frequency to 12.5 Hz */
	odr_attr.val1 = 12.5;
	odr_attr.val2 = 0;

	ret = sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for accelerometer.\n&amp;quot;);
		return ret;
	}

	ret = sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;odr_attr);
	if (ret != 0) {
		printf(&amp;quot;Cannot set sampling frequency for gyro.\n&amp;quot;);
		return ret;
	}

	return 0;
}

#ifdef CONFIG_LSM6DSO_TRIGGER
static void trigger_handler(const struct device *dev,
	const struct sensor_trigger *trig)
{
//static bool led_on = false;
//printf(&amp;quot;Triggered.\n&amp;quot;);
// Toggle LED
//led_on = !led_on;
//gpio_pin_set_dt(&amp;amp;led, led_on);

// Optional: also display sensor data
fetch_and_display(dev);
}



static void test_trigger_mode(const struct device *dev)
{
	struct sensor_trigger trig;
	struct sensor_value threshold;

	if (set_sampling_freq(dev) != 0)
		return;


	
    threshold.val1 = 10;
    threshold.val2 = 0;

	// Set trigger type to threshold
	trig.type = SENSOR_TRIG_DELTA;  
	//trig.type = SENSOR_TRIG_THRESHOLD; 
	trig.chan = SENSOR_CHAN_ACCEL_XYZ;
	//trig.chan = SENSOR_CHAN_GYRO_XYZ;


	if (sensor_trigger_set(dev, &amp;amp;trig, trigger_handler) != 0) {
		printf(&amp;quot;Could not set threshold trigger\n&amp;quot;);
		return;
	}
}


#else
static void test_polling_mode(const struct device *dev)
{
	if (set_sampling_freq(dev) != 0) {
		return;
	}

	while (1) {
		fetch_and_display(dev);
		k_sleep(K_MSEC(1000));
	}
}
#endif

int main(void)
{
	const struct device *const dev = DEVICE_DT_GET_ONE(st_lsm6dso);

	if (!device_is_ready(dev)) {
		printk(&amp;quot;%s: device not ready.\n&amp;quot;, dev-&amp;gt;name);
		return 0;
	}

#ifdef CONFIG_LSM6DSO_TRIGGER
	printf(&amp;quot;Testing LSM6DSO sensor in trigger mode.\n\n&amp;quot;);
	if (!gpio_is_ready_dt(&amp;amp;led)) {
		printk(&amp;quot;LED device not ready\n&amp;quot;);
		return 0;
	}

	if (gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT_ACTIVE) != 0) {
		printk(&amp;quot;Failed to configure LED\n&amp;quot;);
		return 0;
	}

	test_trigger_mode(dev);
#else
	printf(&amp;quot;Testing LSM6DSO sensor in polling mode.\n\n&amp;quot;);
	test_polling_mode(dev);
#endif
	return 0;
}
&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>