<?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>SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110868/spi-communication-with-lis3dh-sensor-nrfconnect-sdk</link><description>Hello, 
 I&amp;#39;m encountering an issue while configuring the SPI bus to communicate with a LIS3DH sensor using nrf52832. I&amp;#39;m working with Visual Studio Code using nrfConnect SDK (Zephyr). 
 
 Here&amp;#39;s the Device Tree Source (DTS): 
 
 // Copyright (c) 2024</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Oct 2024 10:46:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110868/spi-communication-with-lis3dh-sensor-nrfconnect-sdk" /><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/506479?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2024 10:46:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:014dd8bd-ca7c-478b-92ce-ab8b84f2231f</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hi S.M,&lt;/p&gt;
[quote user="S.M"]I noticed only one major change, changed SPI0 to SPI1 are there any issues in that?[/quote]
&lt;p&gt;Certain peripherals share resources and cannot be used simultaneously. For example, the SPI0 and I2C0 peripherals share the same resource, meaning that if I2C0 is enabled, SPI0 cannot be used at the same time, and vice versa. This is why, if I2C0 is being used, you would need to use SPI1 instead of SPI0.&lt;/p&gt;
&lt;p&gt;If Guillaume is building for &lt;code&gt;nrf52dk_nrf52832&lt;/code&gt; then &lt;code&gt;i2c0&lt;/code&gt; is enabled by default.&lt;/p&gt;
&lt;p&gt;If you have an issue that you would like to discuss further, please create a new ticket, and we will be happy to assist you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/506362?ContentTypeID=1</link><pubDate>Tue, 15 Oct 2024 16:35:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15eef0df-2195-48ff-80a1-846b19cc2f3f</guid><dc:creator>S.M</dc:creator><description>&lt;p&gt;Hi Guillaume,&lt;/p&gt;
&lt;p&gt;Thanks for posting the solution.&lt;/p&gt;
&lt;p&gt;I am quite confused, I noticed only one major change, changed SPI0 to SPI1 are there any issues in that?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;S.M&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/502927?ContentTypeID=1</link><pubDate>Wed, 18 Sep 2024 11:45:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2519d2ca-83ff-4b59-b0f0-9ebade11249b</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hi Guillaume,&lt;/p&gt;
&lt;p&gt;Great to hear that it is now working. Thank you for posting the solution.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/502557?ContentTypeID=1</link><pubDate>Mon, 16 Sep 2024 07:45:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11b793f2-f306-4559-b7bc-92df9cd3454e</guid><dc:creator>Guillaume</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s was a DTS file issue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here the good one :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Copyright (c) 2024 Nordic Semiconductor ASA
// SPDX-License-Identifier: Apache-2.0

/dts-v1/;
#include &amp;lt;nordic/nrf52832_qfaa.dtsi&amp;gt;

/ {
	model = &amp;quot;x_x&amp;quot;;
	compatible = &amp;quot;x,x&amp;quot;;

	aliases {
		led0 = &amp;amp;led0;
		led1 = &amp;amp;led1;
		led2 = &amp;amp;led2;
	};

	chosen {
		zephyr,sram = &amp;amp;sram0;
		zephyr,flash = &amp;amp;flash0;
		zephyr,code-partition = &amp;amp;slot0_partition;
	};

	leds{
		compatible = &amp;quot;gpio-leds&amp;quot;; 
		led0: led_0{
			gpios = &amp;lt;&amp;amp;gpio0 10 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Blue LED 0&amp;quot;; 
	    };
		led1: led_1{
			gpios = &amp;lt;&amp;amp;gpio0 9 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Green LED 1&amp;quot;; 
	    };
		led2: led_2{
			gpios = &amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Red LED 2&amp;quot;; 
	    };
	};
};

&amp;amp;flash0 {
	partitions {
		compatible = &amp;quot;fixed-partitions&amp;quot;;
		#address-cells = &amp;lt;1&amp;gt;;
		#size-cells = &amp;lt;1&amp;gt;;

		boot_partition: partition@0 {
			label = &amp;quot;mcuboot&amp;quot;;
			reg = &amp;lt;0x0 0xc000&amp;gt;;
		};
		slot0_partition: partition@c000 {
			label = &amp;quot;image-0&amp;quot;;
			reg = &amp;lt;0xc000 0x32000&amp;gt;;
		};
		slot1_partition: partition@3e000 {
			label = &amp;quot;image-1&amp;quot;;
			reg = &amp;lt;0x3e000 0x32000&amp;gt;;
		};
		scratch_partition: partition@70000 {
			label = &amp;quot;image-scratch&amp;quot;;
			reg = &amp;lt;0x70000 0xa000&amp;gt;;
		};
		storage_partition: partition@7a000 {
			label = &amp;quot;storage&amp;quot;;
			reg = &amp;lt;0x7a000 0x6000&amp;gt;;
		};
	};
};


&amp;amp;gpio0 {
	status = &amp;quot;okay&amp;quot;;
};

&amp;amp;gpiote {
    status = &amp;quot;okay&amp;quot;;
};


&amp;amp;pinctrl {
	spi_master_default: spi_master_default {
		group1 {
            psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 15)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MOSI, 0, 20)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MISO, 0, 19)&amp;gt;;
		};
	};

	spi_master_sleep: spi_master_sleep { 
		group1 {
            psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 15)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MOSI, 0, 20)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MISO, 0, 19)&amp;gt;;
			low-power-enable;
		};
	};
};

lis3dh_spi_master: &amp;amp;spi1 {
	compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
    status = &amp;quot;okay&amp;quot;;
	pinctrl-0 = &amp;lt;&amp;amp;spi_master_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi_master_sleep&amp;gt;;
    pinctrl-names = &amp;quot;default&amp;quot;,&amp;quot;sleep&amp;quot;;
    cs-gpios = &amp;lt;&amp;amp;gpio0 18 GPIO_ACTIVE_LOW&amp;gt;;
    
    reg_lis3dh_master: lis3dh@0{
        compatible = &amp;quot;st,lis2dh&amp;quot;;
        reg = &amp;lt;0&amp;gt;;
        irq-gpios = &amp;lt;&amp;amp;gpio0 16 GPIO_ACTIVE_HIGH&amp;gt;, &amp;lt;&amp;amp;gpio0 17 GPIO_ACTIVE_HIGH&amp;gt;;
        spi-max-frequency = &amp;lt;8000000&amp;gt;;
    };
};&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/502488?ContentTypeID=1</link><pubDate>Fri, 13 Sep 2024 13:14:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43903265-d1bf-4d98-b83f-bcd19546104d</guid><dc:creator>Guillaume</dc:creator><description>&lt;p&gt;Hi Helsing,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;am using nRF Connect SDK v2.6.0.&amp;nbsp;Here the prf.config :&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;pre class="ui-code" data-mode="text"&gt;# SPI
CONFIG_SPI=y
CONFIG_SPI_NRFX=y
CONFIG_NRFX_SPI0=y
CONFIG_SPI_ASYNC=y
CONFIG_CONSOLE=y&lt;/pre&gt;
&lt;div&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;p&gt;I have checked the MOSI, MISO, and SCK lines with an oscilloscope and compared them with the previous code under FreeRTOS I don&amp;#39;t see any differences, the data is good but I don&amp;#39;t have acces on the CS line, so I believe the issue is coming from the CS (Chip Select) line, as indicated by the error message.&lt;/p&gt;
&lt;p&gt;*** Booting nRF Connect SDK v3.5.99-ncs1 ***&lt;br /&gt;SPI master chip select device not ready!&lt;br /&gt;SPI TX: 0x8f&lt;br /&gt;SPI RX: 0xff&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m spi_init() and after&amp;nbsp;&lt;span&gt;spi_write_test_msg&lt;/span&gt;&lt;span&gt;() on the main function.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Here is my updated code:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
&amp;#160;* Copyright (c) 2016 Intel Corporation
&amp;#160;*
&amp;#160;* SPDX-License-Identifier: Apache-2.0
&amp;#160;*/

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS &amp;#160; 1000

#define LIS3DH_OUT_X_L &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;0x28
#define LIS3DH_OUT_X_H &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;0x29

#define MY_SPI_MASTER DT_NODELABEL(lis3dh_spi_master)
#define MY_SPI_MASTER_CS_DT_SPEC SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_lis3dh_master))

#define SPI_BUFSIZE &amp;#160;8 &amp;#160; //SPI Communication buffer size
uint8_t &amp;#160; spi_tx_buf[SPI_BUFSIZE]; // spitx buffer
uint8_t &amp;#160; spi_rx_buf[SPI_BUFSIZE]; // spirx buffer

#define ADD_REG_WHO_AM_I &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;0x0F
#define UC_WHO_AM_I_DEFAULT_VALUE &amp;#160; &amp;#160; &amp;#160; 0x3F
/* set read single command. Attention: command must be 0x3F at most */
#define SET_READ_SINGLE_CMD(x) &amp;#160; &amp;#160; &amp;#160; &amp;#160; (x |0x80)

// SPI master functionality
const struct device *spi_dev;
static struct k_poll_signal spi_done_sig = K_POLL_SIGNAL_INITIALIZER(spi_done_sig);


void printbuffers()
{
&amp;#160; &amp;#160; printk(&amp;quot;SPI TX: &amp;quot;);
&amp;#160; &amp;#160; for (int j = 0; j&amp;lt;sizeof(spi_tx_buf); j++)
&amp;#160; &amp;#160; {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot; %x&amp;quot;,spi_tx_buf[j]);
&amp;#160; &amp;#160; }
&amp;#160; &amp;#160; printk(&amp;quot;\r\nSPI RX: &amp;quot;);
&amp;#160; &amp;#160; for (int j = 0; j&amp;lt;sizeof(spi_rx_buf); j++)
&amp;#160; &amp;#160; {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot; %x&amp;quot;,spi_rx_buf[j]);
&amp;#160; &amp;#160; }
&amp;#160; &amp;#160; printk(&amp;quot;\r\n&amp;quot;);

}


void spi_init(void)
{
&amp;#160; &amp;#160; spi_dev = DEVICE_DT_GET(MY_SPI_MASTER);
&amp;#160; &amp;#160; if(!device_is_ready(spi_dev)) {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot;SPI master device not ready!\n&amp;quot;);
&amp;#160; &amp;#160; }
&amp;#160; &amp;#160; struct gpio_dt_spec spim_cs_gpio = MY_SPI_MASTER_CS_DT_SPEC;
&amp;#160; &amp;#160; if(!device_is_ready(spim_cs_gpio.port)){
&amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot;SPI master chip select device not ready!\n&amp;quot;);
&amp;#160; &amp;#160; }
}

static struct spi_config spi_cfg = {
&amp;#160; &amp;#160; .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA,
&amp;#160; &amp;#160; .frequency = 8000000,
&amp;#160; &amp;#160; .slave = 0,
&amp;#160; &amp;#160; .cs = {.gpio = MY_SPI_MASTER_CS_DT_SPEC, .delay = 2},
};

int spi_write_test_msg(void)
{
&amp;#160; &amp;#160; const struct spi_buf tx_buf = {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .buf = spi_tx_buf,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .len = sizeof(spi_tx_buf)
&amp;#160; &amp;#160; };
&amp;#160; &amp;#160; const struct spi_buf_set tx = {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .buffers = &amp;amp;tx_buf,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .count = 1
&amp;#160; &amp;#160; };

&amp;#160; &amp;#160; struct spi_buf rx_buf = {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .buf = spi_rx_buf,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .len = sizeof(spi_rx_buf),
&amp;#160; &amp;#160; };
&amp;#160; &amp;#160; const struct spi_buf_set rx = {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .buffers = &amp;amp;rx_buf,
&amp;#160; &amp;#160; &amp;#160; &amp;#160; .count = 1
&amp;#160; &amp;#160; };

&amp;#160; &amp;#160; // Update the TX buffer with a rolling counter
&amp;#160; &amp;#160; spi_tx_buf[0] = SET_READ_SINGLE_CMD(ADD_REG_WHO_AM_I);
&amp;#160; &amp;#160; printk(&amp;quot;SPI TX: 0x%.2x\n&amp;quot;, spi_tx_buf[0]);

&amp;#160; &amp;#160; // Reset signal
&amp;#160; &amp;#160; k_poll_signal_reset(&amp;amp;spi_done_sig);
&amp;#160; &amp;#160;
&amp;#160; &amp;#160; // Start transaction
&amp;#160; &amp;#160; int error = spi_transceive_signal(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx, &amp;amp;spi_done_sig);
&amp;#160; &amp;#160; if(error != 0){
&amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot;SPI transceive error: %i\n&amp;quot;, error);
&amp;#160; &amp;#160; &amp;#160; &amp;#160; return error;
&amp;#160; &amp;#160; }

&amp;#160; &amp;#160; // Wait for the done signal to be raised and log the rx buffer
&amp;#160; &amp;#160; int spi_signaled, spi_result;
&amp;#160; &amp;#160; do{
&amp;#160; &amp;#160; &amp;#160; &amp;#160; k_poll_signal_check(&amp;amp;spi_done_sig, &amp;amp;spi_signaled, &amp;amp;spi_result);
&amp;#160; &amp;#160; } while(spi_signaled == 0);
&amp;#160; &amp;#160; printk(&amp;quot;SPI RX: 0x%.2x\n&amp;quot;, spi_rx_buf[1]);

&amp;#160; &amp;#160; if (spi_rx_buf[1] == UC_WHO_AM_I_DEFAULT_VALUE)
&amp;#160; &amp;#160; {
&amp;#160; &amp;#160; &amp;#160; &amp;#160; printk(&amp;quot;LIS3DSH detected rn&amp;quot;);
&amp;#160; &amp;#160; }

&amp;#160; &amp;#160; return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Again the DTS file :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="json"&gt;// Copyright (c) 2024 Nordic Semiconductor ASA
// SPDX-License-Identifier: Apache-2.0

/dts-v1/;
#include &amp;lt;nordic/nrf52832_qfaa.dtsi&amp;gt;

/ {
	model = &amp;quot;x&amp;quot;;
	compatible = &amp;quot;x,x&amp;quot;;

	aliases {
		led0 = &amp;amp;led0;
		led1 = &amp;amp;led1;
		led2 = &amp;amp;led2;
	};
	
	chosen {
		zephyr,sram = &amp;amp;sram0;
		zephyr,flash = &amp;amp;flash0;
		zephyr,code-partition = &amp;amp;slot0_partition;
	};

	leds{
		compatible = &amp;quot;gpio-leds&amp;quot;; 
		led0: led_0{
			gpios = &amp;lt;&amp;amp;gpio0 10 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Blue LED 0&amp;quot;; 
	    };
		led1: led_1{
			gpios = &amp;lt;&amp;amp;gpio0 9 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Green LED 1&amp;quot;; 
	    };
		led2: led_2{
			gpios = &amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Red LED 2&amp;quot;; 
	    };
	};

	reserved-memory {
		#address-cells = &amp;lt;1&amp;gt;;
		#size-cells = &amp;lt;1&amp;gt;;
		ranges;
		memory: memory@20000000 {
			reg = &amp;lt;0x20000000 0x10000&amp;gt;;
		};
	};
};

&amp;amp;flash0 {
	partitions {
		compatible = &amp;quot;fixed-partitions&amp;quot;;
		#address-cells = &amp;lt;1&amp;gt;;
		#size-cells = &amp;lt;1&amp;gt;;

		boot_partition: partition@0 {
			label = &amp;quot;mcuboot&amp;quot;;
			reg = &amp;lt;0x0 0xc000&amp;gt;;
		};
		slot0_partition: partition@c000 {
			label = &amp;quot;image-0&amp;quot;;
			reg = &amp;lt;0xc000 0x32000&amp;gt;;
		};
		slot1_partition: partition@3e000 {
			label = &amp;quot;image-1&amp;quot;;
			reg = &amp;lt;0x3e000 0x32000&amp;gt;;
		};
		scratch_partition: partition@70000 {
			label = &amp;quot;image-scratch&amp;quot;;
			reg = &amp;lt;0x70000 0xa000&amp;gt;;
		};
		storage_partition: partition@7a000 {
			label = &amp;quot;storage&amp;quot;;
			reg = &amp;lt;0x7a000 0x6000&amp;gt;;
		};
	};
};


&amp;amp;gpio0 {
	status = &amp;quot;okay&amp;quot;;
};

&amp;amp;gpiote {
    status = &amp;quot;okay&amp;quot;;
};

lis3dh_spi_master: &amp;amp;spi0 {
	compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
    status = &amp;quot;okay&amp;quot;;
    pinctrl-0 = &amp;lt;&amp;amp;spi0_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi0_sleep&amp;gt;; 
    pinctrl-names = &amp;quot;default&amp;quot;,&amp;quot;sleep&amp;quot;;
    cs-gpios = &amp;lt;&amp;amp;gpio0 18 GPIO_ACTIVE_LOW&amp;gt;;
    
    reg_lis3dh: lis3dh@0{
        compatible = &amp;quot;st,lis2dh&amp;quot;;
        reg = &amp;lt;0&amp;gt;;
        irq-gpios = &amp;lt;&amp;amp;gpio0 16 GPIO_ACTIVE_HIGH&amp;gt;, &amp;lt;&amp;amp;gpio0 17 GPIO_ACTIVE_HIGH&amp;gt;;
        spi-max-frequency = &amp;lt;8000000&amp;gt;;
    };
};

&amp;amp;pinctrl {
    spi0_default: spi0_default {
        group1 {
            psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 15)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MOSI, 0, 20)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MISO, 0, 19)&amp;gt;;

        };
	};
	spi0_sleep: spi0_sleep {
		group1 {
			psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 15)&amp;gt;,
				    &amp;lt;NRF_PSEL(SPIM_MOSI, 0, 20)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MISO, 0, 19)&amp;gt;;
			low-power-enable;
		};	

    };
};

&amp;amp;temp {
	status = &amp;quot;disabled&amp;quot;;
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do you have some ideas ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/489522?ContentTypeID=1</link><pubDate>Wed, 19 Jun 2024 12:57:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f3dc6b6-6594-4189-84d7-0c2d5a4000f7</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hi Guillaume, here are some things to try:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The frequency in spi_cfg is set to 8000000 (8 MHz), whereas in the device tree it is set to 4000000 (4 MHz) in the spi-max-frequency for the lis3dh@0 node. Try to make these two match and see if it improves anything.&lt;/li&gt;
&lt;li&gt;Check the return value of spi_transceive(): The spi_transceive() function returns a negative error code if there&amp;#39;s a problem with the SPI transfer. You can check this return value to get more information about the error.&lt;/li&gt;
&lt;li&gt;Could you try to set the PicoScope to analog and record the output from the SPI pins? Are you not seeing any signals changing/toggeling at all?&lt;/li&gt;
&lt;li&gt;Ensure the SPI driver for NRF52832 is enabled in your &lt;code&gt;prj.conf&lt;/code&gt; file with &lt;code&gt;CONFIG_SPI=y&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Which nRF Connect SDK version are you using?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/489378?ContentTypeID=1</link><pubDate>Tue, 18 Jun 2024 19:01:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:380a4f6c-4646-4b8c-9796-6a1000a5ff03</guid><dc:creator>Guillaume</dc:creator><description>&lt;p&gt;Hi Helsing,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes of course. Here the .dts file :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Copyright (c) 2024 Nordic Semiconductor ASA
// SPDX-License-Identifier: Apache-2.0

/dts-v1/;
#include &amp;lt;nordic/nrf52832_qfaa.dtsi&amp;gt;

/ {
	model = &amp;quot;xxx&amp;quot;;
	compatible = &amp;quot;xxx,xxx&amp;quot;;

	aliases {
		led0 = &amp;amp;led0;
		led1 = &amp;amp;led1;
		led2 = &amp;amp;led2;
	};

	chosen {
		zephyr,sram = &amp;amp;sram0;
		zephyr,flash = &amp;amp;flash0;
		zephyr,code-partition = &amp;amp;slot0_partition;
	};

	leds{
		compatible = &amp;quot;gpio-leds&amp;quot;; 
		led0: led_0{
			gpios = &amp;lt;&amp;amp;gpio0 10 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Blue LED 0&amp;quot;; 
	    };
		led1: led_1{
			gpios = &amp;lt;&amp;amp;gpio0 9 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Green LED 1&amp;quot;; 
	    };
		led2: led_2{
			gpios = &amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;;
			label = &amp;quot;Red LED 2&amp;quot;; 
	    };
	};
};

&amp;amp;flash0 {
	partitions {
		compatible = &amp;quot;fixed-partitions&amp;quot;;
		#address-cells = &amp;lt;1&amp;gt;;
		#size-cells = &amp;lt;1&amp;gt;;

		boot_partition: partition@0 {
			label = &amp;quot;mcuboot&amp;quot;;
			reg = &amp;lt;0x0 0xc000&amp;gt;;
		};
		slot0_partition: partition@c000 {
			label = &amp;quot;image-0&amp;quot;;
			reg = &amp;lt;0xc000 0x32000&amp;gt;;
		};
		slot1_partition: partition@3e000 {
			label = &amp;quot;image-1&amp;quot;;
			reg = &amp;lt;0x3e000 0x32000&amp;gt;;
		};
		scratch_partition: partition@70000 {
			label = &amp;quot;image-scratch&amp;quot;;
			reg = &amp;lt;0x70000 0xa000&amp;gt;;
		};
		storage_partition: partition@7a000 {
			label = &amp;quot;storage&amp;quot;;
			reg = &amp;lt;0x7a000 0x6000&amp;gt;;
		};
	};
};


&amp;amp;gpio0 {
	status = &amp;quot;okay&amp;quot;;
};

&amp;amp;gpiote {
    status = &amp;quot;okay&amp;quot;;
};


&amp;amp;pinctrl {
	spi_master_default: spi_master_default {
		group1 {
            psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 15)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MOSI, 0, 20)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MISO, 0, 19)&amp;gt;;
		};
	};

	spi_master_sleep: spi_master_sleep {
		group1 {
            psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 15)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MOSI, 0, 20)&amp;gt;,
					&amp;lt;NRF_PSEL(SPIM_MISO, 0, 19)&amp;gt;;
			low-power-enable;
		};
	};
};

lis3dh_spi_master: &amp;amp;spi1 {
	compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
    status = &amp;quot;okay&amp;quot;;
	pinctrl-0 = &amp;lt;&amp;amp;spi_master_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi_master_sleep&amp;gt;;
    pinctrl-names = &amp;quot;default&amp;quot;,&amp;quot;sleep&amp;quot;;
    cs-gpios = &amp;lt;&amp;amp;gpio0 18 GPIO_ACTIVE_LOW&amp;gt;;
    
    reg_lis3dh_master: lis3dh@0{
        compatible = &amp;quot;st,lis2dh&amp;quot;;
        reg = &amp;lt;0&amp;gt;;
        irq-gpios = &amp;lt;&amp;amp;gpio0 16 GPIO_ACTIVE_HIGH&amp;gt;, &amp;lt;&amp;amp;gpio0 17 GPIO_ACTIVE_HIGH&amp;gt;;
        spi-max-frequency = &amp;lt;4000000&amp;gt;;
    };
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And here the spi file :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   1000

#define LIS3DH_OUT_X_L                  0x28
#define LIS3DH_OUT_X_H                  0x29

#define MY_SPI_MASTER DT_NODELABEL(lis3dh_spi_master)
#define MY_SPI_MASTER_CS_DT_SPEC SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_lis3dh_master))

// SPI master functionality
const struct device *spi_dev;
static struct k_poll_signal spi_done_sig = K_POLL_SIGNAL_INITIALIZER(spi_done_sig);

static void spi_init(void)
{
	spi_dev = DEVICE_DT_GET(MY_SPI_MASTER);
	if(!device_is_ready(spi_dev)) {
		printk(&amp;quot;SPI master device not ready!\n&amp;quot;);
	}
	struct gpio_dt_spec spim_cs_gpio = MY_SPI_MASTER_CS_DT_SPEC;
	if(!device_is_ready(spim_cs_gpio.port)){
		printk(&amp;quot;SPI master chip select device not ready!\n&amp;quot;);
	}
}

static struct spi_config spi_cfg = {
	.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA,
	.frequency = 8000000,
	.slave = 0,
	.cs = {.gpio = MY_SPI_MASTER_CS_DT_SPEC, .delay = 0},
};

static int spi_write_test_msg(void)
{
	static uint8_t counter = 0;
	static uint8_t tx_buffer[2];
	static uint8_t rx_buffer[2];

	const struct spi_buf tx_buf = {
		.buf = tx_buffer,
		.len = sizeof(tx_buffer)
	};
	const struct spi_buf_set tx = {
		.buffers = &amp;amp;tx_buf,
		.count = 1
	};

	struct spi_buf rx_buf = {
		.buf = rx_buffer,
		.len = sizeof(rx_buffer),
	};
	const struct spi_buf_set rx = {
		.buffers = &amp;amp;rx_buf,
		.count = 1
	};

	// Update the TX buffer with a rolling counter
	tx_buffer[0] = LIS3DH_OUT_X_L ;
	printk(&amp;quot;SPI TX: 0x%.2x, 0x%.2x\n&amp;quot;, tx_buffer[0], tx_buffer[1]);

	// Reset signal
	k_poll_signal_reset(&amp;amp;spi_done_sig);
	
	// Start transaction
	int error = spi_transceive_signal(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx, &amp;amp;spi_done_sig);
	if(error != 0){
		printk(&amp;quot;SPI transceive error: %i\n&amp;quot;, error);
		return error;
	}

	// Wait for the done signal to be raised and log the rx buffer
	int spi_signaled, spi_result;
	do{
		k_poll_signal_check(&amp;amp;spi_done_sig, &amp;amp;spi_signaled, &amp;amp;spi_result);
	} while(spi_signaled == 0);
	printk(&amp;quot;SPI RX: 0x%.2x, 0x%.2x\n&amp;quot;, rx_buffer[0], rx_buffer[1]);
	return 0;
}


int test_spi(void)
{
	int ret;

	spi_init();

	printk(&amp;quot;\n SPI master example started\n&amp;quot;);

		while (1) {
		spi_write_test_msg();
		if (ret &amp;lt; 0) {
			return 0;
		}
		k_msleep(SLEEP_TIME_MS);
	}

	return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For information, I&amp;#39;m using Nrf52832, with lis3dh on SPI communication. It works on SDK5.&lt;/p&gt;
&lt;p&gt;Guillaume&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/487942?ContentTypeID=1</link><pubDate>Fri, 07 Jun 2024 14:35:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:501ec6e4-c3a4-4e63-8726-f58bc98cb8b2</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hi Guillaume,&lt;/p&gt;
[quote user="Guillaume PELLETIER"]I don&amp;#39;t see anything with the PicoScope.[/quote]
&lt;p&gt;Are you not seeing any communication at all?&lt;/p&gt;
&lt;p&gt;Would you be alble to share the .dts file? Or a snippet of your code demonstrating this? &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/486938?ContentTypeID=1</link><pubDate>Fri, 31 May 2024 14:20:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5736a66e-dd4b-470f-b2af-5c12dd02a8da</guid><dc:creator>Guillaume</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks, i don&amp;#39;t have issue for the compilation with this code:&lt;/p&gt;
&lt;div&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/drivers/spi.h&amp;gt;

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   1000

#define LIS3DH_OUT_X_L                  0x28
#define LIS3DH_OUT_X_H                  0x29

#define MY_SPI_MASTER DT_NODELABEL(lis3dh_spi_master)
#define MY_SPI_MASTER_CS_DT_SPEC SPI_CS_GPIOS_DT_SPEC_GET(DT_NODELABEL(reg_lis3dh_master))

// SPI master functionality
const struct device *spi_dev;
static struct k_poll_signal spi_done_sig = K_POLL_SIGNAL_INITIALIZER(spi_done_sig);

static void spi_init(void)
{
    spi_dev = DEVICE_DT_GET(MY_SPI_MASTER);
    if(!device_is_ready(spi_dev)) {
        printk(&amp;quot;SPI master device not ready!\n&amp;quot;);
    }
    struct gpio_dt_spec spim_cs_gpio = MY_SPI_MASTER_CS_DT_SPEC;
    if(!device_is_ready(spim_cs_gpio.port)){
        printk(&amp;quot;SPI master chip select device not ready!\n&amp;quot;);
    }
}

static struct spi_config spi_cfg = {
    .operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB | SPI_MODE_CPOL | SPI_MODE_CPHA,
    .frequency = 8000000,
    .slave = 0,
    .cs = {.gpio = MY_SPI_MASTER_CS_DT_SPEC, .delay = 0},
};

static int spi_write_test_msg(void)
{
    static uint8_t counter = 0;
    static uint8_t tx_buffer[2];
    static uint8_t rx_buffer[2];

    const struct spi_buf tx_buf = {
        .buf = tx_buffer,
        .len = sizeof(tx_buffer)
    };
    const struct spi_buf_set tx = {
        .buffers = &amp;amp;tx_buf,
        .count = 1
    };

    struct spi_buf rx_buf = {
        .buf = rx_buffer,
        .len = sizeof(rx_buffer),
    };
    const struct spi_buf_set rx = {
        .buffers = &amp;amp;rx_buf,
        .count = 1
    };

    // Update the TX buffer with a rolling counter
    tx_buffer[0] = LIS3DH_OUT_X_L;
    printk(&amp;quot;SPI TX: 0x%.2x, 0x%.2x\n&amp;quot;, tx_buffer[0], tx_buffer[1]);

    // Reset signal
    k_poll_signal_reset(&amp;amp;spi_done_sig);
   
    // Start transaction
    int error = spi_transceive_signal(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx, &amp;amp;spi_done_sig);
    if(error != 0){
        printk(&amp;quot;SPI transceive error: %i\n&amp;quot;, error);
        return error;
    }

    // Wait for the done signal to be raised and log the rx buffer
    int spi_signaled, spi_result;
    do{
        k_poll_signal_check(&amp;amp;spi_done_sig, &amp;amp;spi_signaled, &amp;amp;spi_result);
    } while(spi_signaled == 0);
    printk(&amp;quot;SPI RX: 0x%.2x, 0x%.2x\n&amp;quot;, rx_buffer[0], rx_buffer[1]);
    return 0;
}


int test_spi(void)
{
    int ret;

    spi_init();

    printk(&amp;quot;\n SPI master example started\n&amp;quot;);

        while (1) {
        spi_write_test_msg();
        if (ret &amp;lt; 0) {
            return 0;
        }
        k_msleep(SLEEP_TIME_MS);
    }

    return 0;
}

&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;But I only received 0xFF on the RX SPI buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My tag works with nrf5_sdk with Segger and we would like to use Visual Studio Code to use Edge Impulse. (i&amp;nbsp;need to get the accelerometer data to feed the ML.)&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t see anything with the PicoScope. Do you have some idea ? The DTS seem good ...&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EDIT by Helsing&lt;/strong&gt;: Embedding code using Insert-&amp;gt;Code for readability.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI communication with Lis3dh sensor (nrfConnect SDK)</title><link>https://devzone.nordicsemi.com/thread/482086?ContentTypeID=1</link><pubDate>Mon, 06 May 2024 14:28:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d0d6183-d233-46e9-a9ac-3c31466af44b</guid><dc:creator>helsing</dc:creator><description>&lt;p&gt;Hi Guillaume,&lt;/p&gt;
&lt;p&gt;At first glance, it looks like you have omitted a step with the buffer in test_spi(). Check out this SPI sample:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/too1/ncs-spi-master-slave-example/blob/629db4cf8000605ddf46a5ac18936552bae3f52f/src/main.c#L47"&gt;https://github.com/too1/ncs-spi-master-slave-example/blob/629db4cf8000605ddf46a5ac18936552bae3f52f/src/main.c#L47&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>