<?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>BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/98640/bmi270-interrupts-seem-not-to-be-usable-in-nrf-connect-sdk-v2-2-0-with-zephyr</link><description>Hi, 
 I am developing a nrf5340 based board containing the BMI270 IMU device via SPI interface like in the Thingy:53. 
 Unfortunately I am not able to set the device up for using the data ready interrupt and reacting to the interrupt via the zephyr device</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 06 Mar 2024 15:06:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/98640/bmi270-interrupts-seem-not-to-be-usable-in-nrf-connect-sdk-v2-2-0-with-zephyr" /><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/472535?ContentTypeID=1</link><pubDate>Wed, 06 Mar 2024 15:06:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4e7c8b1d-3026-4050-8b77-16c46b6fb9f1</guid><dc:creator>MatiM</dc:creator><description>&lt;p&gt;Thank you very much :D&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/472330?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2024 20:04:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95b0ccd1-e6ef-4bdc-ac39-fc0aad13db4b</guid><dc:creator>nfbe</dc:creator><description>&lt;p&gt;Hi MatiM,&lt;/p&gt;
&lt;p&gt;I cannot share the full code with you, but some snippets and the concept, I think. Currently I am running it unter nRF Connect SDK v2.4.0 - and I have not checked, if any new version of the driver&amp;nbsp;now is supporting the interrupts.&lt;/p&gt;
&lt;p&gt;So her are the snippets of my code (from a test version) - with everything referencing my project removed - so there are some includes removed and some short specifics of the code, but I hope it is still a guide&amp;nbsp;helping you along with all related to interrupt processing included...&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;
#include &amp;lt;zephyr/drivers/sensor.h&amp;gt;

#include &amp;quot;BMI270.h&amp;quot;
#include &amp;quot;leds_IO_power.h&amp;quot;

// setup GPIO-PIN for BMI270 interrupts
#define GPIO_BMI270_INT1 12
#define GPIO_BMI270_INT2 28

// setup some structs for BMI270 interrupt callbacks
static struct gpio_callback BMI270_int1_cb_data;
static struct gpio_callback BMI270_int2_cb_data;

// counters increased by the interrupts, decreased by the reaction
atomic_t BMI270_int1_cnt;	// atomic avariables are always initialized to zero
atomic_t BMI270_int2_cnt;	// atomic avariables are always initialized to zero

// store reference to sensor device
const struct device *const sensor_device = DEVICE_DT_GET_ONE(bosch_bmi270);

// interrupt callbacks for BMI270
void BMI270_int1_callback(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins)
{
	atomic_inc(&amp;amp;BMI270_int1_cnt);
}

void BMI270_int2_callback(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins)
{
	atomic_inc(&amp;amp;BMI270_int2_cnt);
}

int setup_BMI270_interrupt1(void)
{
	int err = 0;

	if(!device_is_ready(gpio0Dev))
		err = -ENODEV;
	else
	{
		err = gpio_pin_configure(gpio0Dev, GPIO_BMI270_INT1, GPIO_INPUT | GPIO_ACTIVE_LOW);
		if(!err)
		{
			err = gpio_pin_interrupt_configure(gpio0Dev, GPIO_BMI270_INT1, GPIO_INT_EDGE_TO_ACTIVE);
			if(!err)
			{
				gpio_init_callback(&amp;amp;BMI270_int1_cb_data, BMI270_int1_callback, BIT(GPIO_BMI270_INT1));
				err = gpio_add_callback(gpio0Dev, &amp;amp;BMI270_int1_cb_data);
			}
		}
	}

	return(err);
}

int setup_BMI270_interrupt2(void)
{
	int err = 0;

	if(!device_is_ready(gpio0Dev))
		err = -ENODEV;
	else
	{
		err = gpio_pin_configure(gpio0Dev, GPIO_BMI270_INT2, GPIO_INPUT | GPIO_ACTIVE_LOW);
		if(!err)
		{
			err = gpio_pin_interrupt_configure(gpio0Dev, GPIO_BMI270_INT2, GPIO_INT_EDGE_TO_ACTIVE);
			if(!err)
			{
				gpio_init_callback(&amp;amp;BMI270_int2_cb_data, BMI270_int2_callback, BIT(GPIO_BMI270_INT2));
				err = gpio_add_callback(gpio0Dev, &amp;amp;BMI270_int2_cb_data);
			}
		}
	}

	return(err);
}

int setup_bmi270(void)
{
	const struct bmi270_config *cfg;
	uint8_t bmi_data_8;
 	struct sensor_value full_scale, sampling_freq, oversampling;

    int err = 0;

	if (!device_is_ready(sensor_device))
    {
        err = -1;
		return(err);
	}

    // -------- setting up acceleration detection -----------------------------
	// Setting scale in G, due to loss of precision, if SI unit m/s^2 is used
	full_scale.val1 = (int)(BMI270_ACC_RANGE);   // set in G
	full_scale.val2 = (int)((BMI270_ACC_RANGE - full_scale.val1) * 1000000.0);
	sampling_freq.val1 = (int)(BMI270_SAMPLING_FREQUENCY); // in Hz
	sampling_freq.val2 = (int)((BMI270_SAMPLING_FREQUENCY - sampling_freq.val1)
                                                             * 1000000.0);
	oversampling.val1 = 1;
	oversampling.val2 = 0;

	sensor_attr_set(sensor_device, SENSOR_CHAN_ACCEL_XYZ, 
                    SENSOR_ATTR_FULL_SCALE, &amp;amp;full_scale);
	sensor_attr_set(sensor_device, SENSOR_CHAN_ACCEL_XYZ,
                    SENSOR_ATTR_OVERSAMPLING, &amp;amp;oversampling);
	// Set sampling frequency last as this also sets the appropriate power
    // mode. If already sampling, change to 0.0Hz before changing other 
    // attributes
	sensor_attr_set(sensor_device, SENSOR_CHAN_ACCEL_XYZ,
			        SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;sampling_freq);

    // ---------- setting up yaw rate detection -------------------------------
	// Setting scale in degrees/s to match the sensor scale
	full_scale.val1 = (int)(BMI270_GYR_RANGE);                   // dps
	full_scale.val2 = (int)((BMI270_GYR_RANGE - full_scale.val1) * 1000000.0);
	sampling_freq.val1 = (int)(BMI270_SAMPLING_FREQUENCY);       // in Hz 
	sampling_freq.val2 = (int)((BMI270_SAMPLING_FREQUENCY - sampling_freq.val1)
                                                            * 1000000.0);
	oversampling.val1 = 1;                                       
	oversampling.val2 = 0;

	sensor_attr_set(sensor_device, SENSOR_CHAN_GYRO_XYZ,
                    SENSOR_ATTR_FULL_SCALE, &amp;amp;full_scale);
	sensor_attr_set(sensor_device, SENSOR_CHAN_GYRO_XYZ,
                    SENSOR_ATTR_OVERSAMPLING, &amp;amp;oversampling);
	// Set sampling frequency last as this also sets the appropriate power
    // mode. If already sampling, change to 0.0Hz before changing other 
    // attributes
	sensor_attr_set(sensor_device, SENSOR_CHAN_GYRO_XYZ,
			        SENSOR_ATTR_SAMPLING_FREQUENCY, &amp;amp;sampling_freq);

 	// ---------- change Register for interrupt data mapping and check --------

	// write BMI270_REG_INT_MAP_DATA for putting drdy interupt to int1

	bmi_data_8 = 0x04; // map drdy to int1
	err = cfg-&amp;gt;bus_io-&amp;gt;write(&amp;amp;cfg-&amp;gt;bus,BMI270_REG_INT_MAP_DATA,&amp;amp;bmi_data_8, 1);
	if(err)
		printk(&amp;quot;error writing BMI270_REG_INT_MAP_DATA to BMI270: %d\n&amp;quot;, err);
	else
		printk(&amp;quot;value of 0x%x was written to BMI270_REG_INT_MAP_DATA\n&amp;quot;, 
                                                             bmi_data_8);

	// read BMI270_REG_INT_MAP_DATA
	err = cfg-&amp;gt;bus_io-&amp;gt;read(&amp;amp;cfg-&amp;gt;bus, BMI270_REG_INT_MAP_DATA,&amp;amp;bmi_data_8, 1);
	if(err)
		printk(&amp;quot;error reading BMI270_REG_INT_MAP_DATA from BMI270: %d\n&amp;quot;, err);
	else
		printk(&amp;quot;current value of BMI270_REG_INT_MAP_DATA is 0x%02x\n&amp;quot;, 
                                                             bmi_data_8);

	bmi_data_8 = 0x08; // enable int1 as active low in push-pull mode
	err = cfg-&amp;gt;bus_io-&amp;gt;write(&amp;amp;cfg-&amp;gt;bus,BMI270_REG_INT1_IO_CTRL,&amp;amp;bmi_data_8, 1);
	if(err)
		printk(&amp;quot;error writing BMI270_REG_INT1_IO_CTRL to BMI270: %d\n&amp;quot;, err);
	else
		printk(&amp;quot;value of 0x%x was written to BMI270_REG_INT1_IO_CTRL\n&amp;quot;,
                                                             bmi_data_8);

	// read BMI270_REG_INT1_IO_CTRL
	err = cfg-&amp;gt;bus_io-&amp;gt;read(&amp;amp;cfg-&amp;gt;bus, BMI270_REG_INT1_IO_CTRL,&amp;amp;bmi_data_8, 1);
	if(err)
		printk(&amp;quot;error reading BMI270_REG_INT1_IO_CTRL from BMI270: %d\n&amp;quot;, err);
	else
		printk(&amp;quot;current value of BMI270_REG_INT1_IO_CTRL is 0x%02x\n&amp;quot;,
                                                             bmi_data_8);

    err = setup_BMI270_interrupt1();
	if(err)
	{
		printk(&amp;quot;ERROR starting up BMI270 interrupt1 handling (%d)\n&amp;quot;, err);
	}

	err = setup_BMI270_interrupt2();
	if(err)
	{
		printk(&amp;quot;ERROR starting up BMI270 interrupt2 handling (%d)\n&amp;quot;, err);
	}

    return(err);
}

int wait_for_drdy(void)
{
    while(atomic_get(&amp;amp;BMI270_int1_cnt) &amp;lt;= 0)
    {
        // this is intended to be empty - it is a waiting function
    }

    // returns the counter after decrement 
	return(atomic_dec(&amp;amp;BMI270_int1_cnt) - 1);
}

void clear_bmi270(void)
{
    atomic_set(&amp;amp;BMI270_int1_cnt, 0);
}

int read_bmi270_data(struct imuSensorDataStruct *sensorData)
{
	struct bmi270_data *imu_data;
    int err = 0;

    if(!(err = sensor_sample_fetch(sensor_device)))
    {
 		imu_data = sensor_device-&amp;gt;data;
		sensorData-&amp;gt;a.x = imu_data-&amp;gt;ax;
		sensorData-&amp;gt;a.y = imu_data-&amp;gt;ay;
		sensorData-&amp;gt;a.z = imu_data-&amp;gt;az;
		sensorData-&amp;gt;g.x = imu_data-&amp;gt;gx;
		sensorData-&amp;gt;g.y = imu_data-&amp;gt;gy;
		sensorData-&amp;gt;g.z = imu_data-&amp;gt;gz;
    }
    return(err);
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The easiest way to use this in a test, would be to call &amp;quot;setup_bmi270&amp;quot; and then &amp;quot;wait_for_drdy&amp;quot; in a loop and &amp;quot;read_bmi270_data&amp;quot;. On the HW side you would need to connect the BMI270 interrupts to the defined pins and configure those accordingly and you need to setup &amp;quot;Bosch_bmi270&amp;quot; for use with SPI in the device tree, of course.&lt;/p&gt;
&lt;p&gt;I hope, this is of some help to you.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Jens&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/472171?ContentTypeID=1</link><pubDate>Tue, 05 Mar 2024 07:49:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2651fcfd-0750-4f55-ba4a-9fd123e07679</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;In case you don&amp;#39;t get a response here MatiM, feel free to open a new ticket for this. We&amp;#39;ll be happy to help.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/472133?ContentTypeID=1</link><pubDate>Mon, 04 Mar 2024 18:43:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b50a6abe-d0c4-45d6-90ce-418a5ab9d08f</guid><dc:creator>MatiM</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;would it be possible for you to share your solution for interrupt handling with BMI270?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/421826?ContentTypeID=1</link><pubDate>Fri, 21 Apr 2023 15:31:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1a9f6fd-d5db-4fce-b165-92645d3e0960</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Great!&lt;/p&gt;
&lt;p&gt;Glad to hear that it got solved, and I&amp;#39;ll forward this request to the relevant people.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/420859?ContentTypeID=1</link><pubDate>Mon, 17 Apr 2023 19:29:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5e07fc8-0633-495a-9058-0e4d51bf49c6</guid><dc:creator>nfbe</dc:creator><description>&lt;p&gt;Hi Elfving,&lt;br /&gt;I took a look at the BMI270 driver code and used that device specific knowledge to write my own little functions to set the needed registers etc.. and I am using the Standard GPIO-interrupt as you suggested. So my code works for now. But still it would be great, if these functions would officially be exposed through the attributes you can set in the sensor driver in some later version of zephyr and the SDK.&lt;/p&gt;
&lt;p&gt;Thanks a lot for your support. I think this ticket can be closed now.&lt;/p&gt;
&lt;p&gt;Regards, Jens&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/420346?ContentTypeID=1</link><pubDate>Thu, 13 Apr 2023 19:48:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1dff9d0a-ce67-4455-ba1c-e322e9f3ef35</guid><dc:creator>nfbe</dc:creator><description>&lt;p&gt;Hi Elfving,&lt;/p&gt;
&lt;p&gt;Thank you very much for your answer. I have thought of using the pins as you suggested before I wrote my post. But I hesitated, because BMI270 will not simply send interrupts, but needs to be configured to do so by setting registers via SPI. I have not tried yet, but I was assuming that I cannot combine the BMI270 driver with the zephyr SPI driver for the same device - or can I?&lt;/p&gt;
&lt;p&gt;As for the Thingy:53 - I was only thinking that you might be using it in some way (or have tried using it), but I did not find any source on the net that uses this BMI270 interrupt line of the nrf5340 and the current device tree file you provide for the sdk does not show any entry for the interrupt (there is one for the first device, but the BMI270 is not set for interrupt in this tree).&lt;/p&gt;
&lt;p&gt;&amp;amp;spi3 {&lt;br /&gt; compatible = &amp;quot;nordic,nrf-spim&amp;quot;;&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt; cs-gpios = &amp;lt;&amp;amp;gpio0 22 GPIO_ACTIVE_LOW&amp;gt;,&lt;br /&gt; &amp;lt;&amp;amp;gpio1 4 GPIO_ACTIVE_LOW&amp;gt;,&lt;br /&gt; &amp;lt;&amp;amp;gpio0 24 GPIO_ACTIVE_LOW&amp;gt;;&lt;/p&gt;
&lt;p&gt;pinctrl-0 = &amp;lt;&amp;amp;spi3_default&amp;gt;;&lt;br /&gt; pinctrl-1 = &amp;lt;&amp;amp;spi3_sleep&amp;gt;;&lt;br /&gt; pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;&lt;/p&gt;
&lt;p&gt;adxl362: spi-dev-adxl362@0 {&lt;br /&gt; compatible = &amp;quot;adi,adxl362&amp;quot;;&lt;br /&gt; spi-max-frequency = &amp;lt;8000000&amp;gt;;&lt;br /&gt; reg = &amp;lt;0&amp;gt;;&lt;br /&gt; int1-gpios = &amp;lt;&amp;amp;gpio0 19 0&amp;gt;;&lt;br /&gt; };&lt;/p&gt;
&lt;p&gt;bmi270: spi-dev-bmi270@1 {&lt;br /&gt; compatible = &amp;quot;bosch,bmi270&amp;quot;;&lt;br /&gt; status = &amp;quot;disabled&amp;quot;;&lt;br /&gt; spi-max-frequency = &amp;lt;8000000&amp;gt;;&lt;br /&gt; reg = &amp;lt;1&amp;gt;;&lt;br /&gt; };&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;That was the reason for my question for a BMI270 example - I thought, maybe there might be something you plan to implement in the next version or you have some unofficial example code I could take a look at...&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ccffcc;"&gt;Now, what&amp;#39;s left of my question is:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="background-color:#ccffcc;"&gt;Do I have to abandon the BMI270 driver completely, if I need to use SPI communication to set registers in the device that is not supported by the device&amp;#39;s driver, or can I mix drivers (pure SPI with the device specific one) on the same device? How would I configure that in the device tree?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your comments.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Jens&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/420294?ContentTypeID=1</link><pubDate>Thu, 13 Apr 2023 14:19:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2acaadb2-cc5c-453d-9458-9ce908169808</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello again, and thank you for your patience.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;First of all f&lt;a href="https://devzone.nordicsemi.com/support-private/support/297109#permalink=798864"&gt;or&amp;nbsp;some SPI interrupt examples, have a look here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The cleanest way would probably be to modify the sensor driver, but the easiest would be to add the interrupt pin as an &lt;a href="https://academy.nordicsemi.com/topic/gpio-generic-api/"&gt;interrupt&amp;nbsp;GPIO&lt;/a&gt;, and when triggered add reading the sensor value using sensor_sample_fetch() to a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/zbus/work_queue/README.html"&gt;workqueue&lt;/a&gt;.&lt;/p&gt;
[quote user=""]&lt;p&gt;How is the BMI270 interrupt line 1 (that is connected in the schematics) used in the thingy:53 software?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Which software are you referring to? I believe it&amp;nbsp;might just be included so that you can use it if you want to, not that we need to use it in&amp;nbsp;one particular use-case.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BMI270 interrupts seem not to be usable in nRF Connect SDK v2.2.0 with zephyr</title><link>https://devzone.nordicsemi.com/thread/419988?ContentTypeID=1</link><pubDate>Wed, 12 Apr 2023 13:51:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab15a181-9626-4050-adcc-b771ab753e96</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello Jens,&lt;/p&gt;
&lt;p&gt;I will have to get back to you on this.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>