<?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 slave on NCS v2.0.0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89768/spi-slave-on-ncs-v2-0-0</link><description>Hi 
 I am trying to migrate my project to newest NCS v2.0.0 but is struggling figuring out how to configure SPI2 slave operation mode. 
 The project is currently running v1.9.1 with calls direct to nrfx_spis.c driver using the following i prj.conf 
 CONFIG_SPI</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 11 Aug 2022 13:47:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89768/spi-slave-on-ncs-v2-0-0" /><item><title>RE: SPI slave on NCS v2.0.0</title><link>https://devzone.nordicsemi.com/thread/381212?ContentTypeID=1</link><pubDate>Thu, 11 Aug 2022 13:47:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28ac98fc-dea0-4585-8cc0-e45846713fc2</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Ok, thanks for reporting back. You&amp;#39;re welcome!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave on NCS v2.0.0</title><link>https://devzone.nordicsemi.com/thread/380968?ContentTypeID=1</link><pubDate>Wed, 10 Aug 2022 09:21:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df24b6e7-b78a-43be-90da-0c028fdb0464</guid><dc:creator>Anders Esbensen</dc:creator><description>&lt;p&gt;Update:&amp;nbsp; &amp;nbsp;I got it working using NCS v2.0.0 using the&amp;nbsp;&lt;span&gt;&amp;nbsp;nrfx_spi api directly.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your support&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave on NCS v2.0.0</title><link>https://devzone.nordicsemi.com/thread/380847?ContentTypeID=1</link><pubDate>Tue, 09 Aug 2022 13:12:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4633818-7b10-4d50-81df-a1a30e0bee8c</guid><dc:creator>Anders Esbensen</dc:creator><description>&lt;p&gt;Hi Stian&lt;/p&gt;
&lt;p&gt;Thank you for the answer. I have been on vacation so haven&amp;#39;t been able to verify until now.&lt;/p&gt;
&lt;p&gt;The prj.conf and dts declaration above helped me build my project using NCS v2.0.0.&lt;/p&gt;
&lt;p&gt;However I would&amp;nbsp; prefer to use the nrfx_spi api directly due to the design of the SPI protocol in use.&lt;/p&gt;
&lt;p&gt;Can you confirm this is still feasible ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave on NCS v2.0.0</title><link>https://devzone.nordicsemi.com/thread/377148?ContentTypeID=1</link><pubDate>Fri, 15 Jul 2022 10:17:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d460711-a3d5-454a-9dd6-02e40b53a4f0</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, this has changed a bit in NCS 2.0.0. Here is an example that works on the nRF52840 DK:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;main.c&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;
#include &amp;lt;device.h&amp;gt;

const struct device * spi_dev;
static struct spi_config spi_cfg = {
	.operation = SPI_WORD_SET(8)
	         | SPI_OP_MODE_SLAVE
             | SPI_TRANSFER_MSB
             //| SPI_MODE_CPOL
             //| SPI_MODE_CPHA
             ,
	.frequency = 4000000,
	.slave = 1,
};

static struct spi_buf rx;
const struct spi_buf_set rx_bufs = {
	.buffers = &amp;amp;rx,
	.count = 1
};

static struct spi_buf tx;
const struct spi_buf_set tx_bufs = {
	.buffers = &amp;amp;tx,
	.count = 1
};

static void spi_init(void)
{
	spi_dev = device_get_binding(DT_LABEL(DT_NODELABEL(spi2)));
}
void spi_test_send(void)
{
	int err;
	static uint8_t tx_buffer[2] = {0x2A, 0xF0};
	tx.buf = tx_buffer;
	tx.len = sizeof(tx_buffer);

	static uint8_t rx_buffer[2];
	rx.buf = rx_buffer;
	rx.len = sizeof(rx_buffer);

	err = spi_transceive(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx_bufs, &amp;amp;rx_bufs);
	if (err &amp;lt; 0) {
		printk(&amp;quot;SPI error: %d\n&amp;quot;, err);
	} else {
		printk(&amp;quot;RX recv:&amp;quot;);
		for (int i = 0; i &amp;lt; err; i++){
			printk(&amp;quot; %x&amp;quot;, rx_buffer[i]);
		}
		printk(&amp;quot;\n&amp;quot;);
	}
}
void main(void)
{
    spi_init();

	while (1) {
		k_msleep(1000);
        spi_test_send();
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;prj.conf&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y
CONFIG_SPI=y
CONFIG_SPI_NRFX=y
CONFIG_SPI_SLAVE=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;nrf52840dk_nrf52840.overlay&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi2 {
    compatible = &amp;quot;nordic,nrf-spis&amp;quot;;
    status = &amp;quot;okay&amp;quot;;
    pinctrl-0 = &amp;lt;&amp;amp;spi2_default_new&amp;gt;;
    pinctrl-1 = &amp;lt;&amp;amp;spi2_sleep_new&amp;gt;;
    def-char = &amp;lt;0xAA&amp;gt;;
};

&amp;amp;pinctrl {
    spi2_default_new: spi2_defalt_new {
        group1 {
            psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 3)&amp;gt;,
                    &amp;lt;NRF_PSEL(SPIM_MISO, 0, 4)&amp;gt;,
                    &amp;lt;NRF_PSEL(SPIM_MOSI, 0, 28)&amp;gt;,
                    &amp;lt;NRF_PSEL(SPIS_CSN, 0, 29)&amp;gt;;
        };
    };
    spi2_sleep_new: spi2_sleep_new {
        group1 {
            psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 3)&amp;gt;,
                    &amp;lt;NRF_PSEL(SPIM_MISO, 0, 4)&amp;gt;,
                    &amp;lt;NRF_PSEL(SPIM_MOSI, 0, 28)&amp;gt;,
                    &amp;lt;NRF_PSEL(SPIS_CSN, 0, 29)&amp;gt;;
        };
    };
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This code is inspired by the zephyr/sample/bluetooth/hci_spi project. So you can have a look at that project for more details.&lt;/p&gt;
&lt;p&gt;Complete project: &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/4532.spis.zip"&gt;devzone.nordicsemi.com/.../4532.spis.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>