<?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>issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69269/issues-with-implementing-spi-slave-on-nrf9160dk</link><description>using nrf connect sdk 1.4.0 and nrf9160 DK 
 build: nrf9160dk_nrf9160ns 
 SES version: V5.10d 
 Windows 10 Pro 64bit 
 
 1. Please note I used https_client project to implement spi slave(but have removed all the https code.. ignore the cert file) 
 2</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 18 Apr 2023 07:52:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69269/issues-with-implementing-spi-slave-on-nrf9160dk" /><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/420926?ContentTypeID=1</link><pubDate>Tue, 18 Apr 2023 07:52:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c40a8c6-40f8-4be7-8fe6-b76c5b2d53b0</guid><dc:creator>Harsh Jain`</dc:creator><description>&lt;p&gt;Can you please bundle the project and share that for reference. It would be really helpful for any one who is beginner in this area.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/285502?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 06:08:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcc2960d-48c9-4078-8a70-6fc92e9bcbde</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;thank you for all the details.. I have a spi master (nrf5340) talking to nrf9160 (slave) all day long now.. I appreciate all the help though I did not expect it to take this long (I have used nrf51 and 52/0 and it took me few minutes :-)..you can close the ticket..&lt;br /&gt;&lt;br /&gt;If it is of interest, I can post the code.. but hopefully, you will have an official sample source soo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/285345?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 13:45:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:efd716d5-94ad-4809-bede-6e4648cb23bd</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you use my former section, the cs-gpios pin number is hard-coded in the SPIM source code side (see spi_cs variable).&lt;/p&gt;
&lt;p&gt;What you can do to derive it &lt;a href="https://docs.zephyrproject.org/latest/guides/dts/api-usage.html"&gt;from DTS&lt;/a&gt; is this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;struct spi_cs_control spi_cs = {
	.gpio_pin = DT_GPIO_PIN_BY_IDX(DT_NODELABEL(spi1), cs_gpios, 0),
	.gpio_dt_flags = GPIO_ACTIVE_LOW,
	.delay = 0,
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then it shall follow what you set in the &amp;quot;cs-gpios&amp;quot; in your overlay file.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The reason why cs-gpios is a bit hard to setup here is because the NRF_SPIMx peripheral does not have a CSN pin. It is expected from the hardware side that you use a generic GPIO as your CSN pin, and if you have several slaves on the bus; you&amp;#39;re also using more CSN pins.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For the slave side, NRF_SPIS, this has the CSN pin in the hardware peripheral, and you should set that using the DTS property &amp;quot;csn-pin&amp;quot;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Summarized:&lt;/p&gt;
&lt;p&gt;compatible = &amp;quot;nordic,nrf-spim&amp;quot; -&amp;gt; use cs-gpios&lt;/p&gt;
&lt;p&gt;compatible = &amp;quot;nordic,nrf-spis&amp;quot; -&amp;gt; use csn-pin&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind 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: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/285170?ContentTypeID=1</link><pubDate>Tue, 15 Dec 2020 16:55:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4031a649-69c7-4f7a-bbb6-1e7b9fa91908</guid><dc:creator>sshenoy105</dc:creator><description>&lt;div class="content full threaded-reply-content user-defined-markup"&gt;
&lt;div class="content"&gt;
&lt;p&gt;&lt;strong&gt;Or you can&amp;nbsp;populate the .cs member of spi_cfg like I have here, which lets the spi-function take care of the csn pin:&lt;br /&gt;&lt;/strong&gt;that&amp;#39;s the route I will prefer to take.. will report the status asap.. I had some trouble getting my logic analyzer going and hence no waveforms yet.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Can you also please confirm if i repeat the same for the slave side too ?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;if we have to use your method for getting CS pin to work -&amp;nbsp; what&amp;#39;s the value of entering CS details in the overlay structure ? and it looks like cthe way to enter s pin details for nrf5340 and nrf9160 are different&lt;br /&gt;&lt;br /&gt;for nrf5340&lt;br /&gt;&amp;amp;spi1 {&lt;br /&gt;compatible = &amp;quot;nordic,nrf-spim&amp;quot;;&lt;br /&gt;status = &amp;quot;okay&amp;quot;;&lt;br /&gt;mosi-pin = &amp;lt;4&amp;gt;;&lt;br /&gt;miso-pin = &amp;lt;10&amp;gt;; //&amp;lt;5&amp;gt;;&lt;br /&gt;sck-pin = &amp;lt;6&amp;gt;;&lt;br /&gt;&lt;strong&gt;cs-gpios = &amp;lt;&amp;amp;gpio0 7 0&amp;gt;;&lt;/strong&gt;&lt;br /&gt;//csn-pin = &amp;lt;7&amp;gt;; DOES NOT WORK as project can not be opened&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and for nrf9160DK&lt;br /&gt;&amp;amp;spi3 {&lt;br /&gt;compatible = &amp;quot;nordic,nrf-spis&amp;quot;;&lt;br /&gt;status = &amp;quot;okay&amp;quot;;&lt;br /&gt;mosi-pin = &amp;lt;10&amp;gt;;&lt;br /&gt;miso-pin = &amp;lt;11&amp;gt;;&lt;br /&gt;sck-pin = &amp;lt;12&amp;gt;;&lt;br /&gt;//cs-gpios = &amp;lt;&amp;amp;gpio0 13 0&amp;gt;; //DOES NOT WORK as project can not be opened&lt;br /&gt;&lt;strong&gt;csn-pin = &amp;lt;13&amp;gt;;&lt;/strong&gt;&lt;br /&gt;def-char = &amp;lt;0xde&amp;gt;;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;in order for me to use your method, do I have to remove&amp;nbsp;chip select pin&amp;nbsp;&amp;nbsp;entries from overlay structure ?&lt;/strong&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/285155?ContentTypeID=1</link><pubDate>Tue, 15 Dec 2020 15:58:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63fe8fd8-1ab0-4145-b73c-f419e5d19a39</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My apologies for not spotting this earlier. Yes, your csn pin isn&amp;#39;t configured.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Are you able to get the csn gpio to be set active/inactive?&lt;/p&gt;
&lt;p&gt;You can&amp;nbsp;add CSN pin handling directly in the application:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define CSN_PIN_OF_CHOICE 30 // Change this to your liking

struct device *dev;
dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
gpio_pin_configure(dev, CSN_PIN_OF_CHOICE, GPIO_OUTPUT);
gpio_pin_set(dev, CSN_PIN_OF_CHOICE, 1);

...
gpio_pin_set(dev, CSN_PIN_OF_CHOICE, 0);
spi_transceive(..);
gpio_pin_set(dev, CSN_PIN_OF_CHOICE, 1);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Or you can&amp;nbsp;populate the .cs member of spi_cfg like I have here, which lets the spi-function take care of the csn pin:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;
/* You can choose any other unused GPIO here as gpio_pin */
struct spi_cs_control spi_cs = {
	.gpio_pin = 14,
	.gpio_dt_flags = GPIO_ACTIVE_LOW,
	.delay = 0,
};

static const struct spi_config spi_cfg = {
	.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
		     SPI_MODE_CPOL | SPI_MODE_CPHA,
	.frequency = 4000000,
	.slave = 0,
	.cs = &amp;amp;spi_cs,
};

struct device * spi_dev;

static void spi_init(void)
{
	const char* const spiName = &amp;quot;SPI_1&amp;quot;;
	
	spi_cs.gpio_dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
	if (spi_cs.gpio_dev == NULL) {
	    printk(&amp;quot;Could not get GPIO_0 device\n&amp;quot;);
	}
	spi_dev = device_get_binding(spiName);

	if (spi_dev == NULL) {
		printk(&amp;quot;Could not get %s device\n&amp;quot;, spiName);
		return;
	}
}

void spi_test_send(void)
{
	int err;
	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
	};

	err = spi_transceive(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);
	if (err) {
		printk(&amp;quot;SPI error: %d\n&amp;quot;, err);
	} else {
		/* Connect MISO to MOSI for loopback */
		printk(&amp;quot;TX sent: %x\n&amp;quot;, tx_buffer[0]);
		printk(&amp;quot;RX recv: %x\n&amp;quot;, rx_buffer[0]);
		tx_buffer[0]++;
	}
}

void main(void)
{
	printk(&amp;quot;SPIM Example\n&amp;quot;);
	spi_init();

	while (1) {
		spi_test_send();
		k_sleep(K_MSEC(1000));
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do note the initialization of&amp;nbsp;&lt;span&gt;spi_cs&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;gpio_dev&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;device_get_binding&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;&amp;quot;GPIO_0&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;; in spi_init().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Which should give you a signal that looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/4456.pastedimage1608047723065v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;1. clock, 2. MOSI, 3. MISO (nothing connected here) 4. CSN&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The CSN pin is hard-coded to GPIO P0.14 here, but you can freely change this to any unused GPIO. On the nRF9160-DK, this specific pin is used for UART, so the next available one is P0.16, I believe.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind 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: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284884?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2020 19:04:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c2ddd6a-7666-4276-b5b6-f4911ef84ee3</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;that&amp;#39;s what I will be doing today to check connectivity and make sure basic spi setup is ok hardware wise.. In the meantime, can you please confirm what&amp;#39;s the corerct way to define&lt;strong&gt; Chip select pin when I use 1.4.0?&amp;nbsp;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I tried csn-pin which seemed to compile on one laptop but wouldn&amp;#39;t on another (same ncs being used) Something like &lt;strong&gt;cs-gpios = &amp;lt;&amp;amp;gpio0 7 0&amp;gt;; seemed to help ..&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I would need advice on defining chip select pins correctly for nrf5340 and nrf9160 while using ncs 1.4.0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284822?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2020 14:38:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ae4894c-ad31-43b7-9b92-b059c6fa5d33</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried scoping the pins, using a oscilloscope or logic analyzer, to see how the communication looks?&lt;/p&gt;
&lt;p&gt;It almost sounds like one of the signals isn&amp;#39;t properly connected or read.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind 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: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284671?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2020 00:56:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a205c85-2bda-41be-ae45-b64f944aa250</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;I am not sure if I replying&amp;nbsp; to the subthread or to the main question (my intention is to add info to my last reply but no longer sure.. looks like the format has changed recently)..&lt;br /&gt;&lt;br /&gt;I think I am getting multiple calls to the handler (way more than two that are expected per call.. one for buffer set and one for transaction complete) probably due to loose contact. I will get confirmation once I have that inspected in my lab tomrrow.. but any feedback from you is appreciated (based on the code submitted)..&lt;br /&gt;&lt;br /&gt;More importantly, my slave tries to send data back which is never recieved by master..&amp;nbsp; I do see master sending data and slave recieves it (even with the issue of multiple calls to the handler),.. I checked and confirm that my tx_buffer on slave side has the correct data .. but I don;t see it recieved by master (the rx bffer of thge master is empty/hasjunk).. is there anything else I need to do in my master/slave code in addition to what I have already done ? tx/rx buffers on both sides are of size 21 and i checked it&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284610?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2020 17:25:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ae9dd69-c51b-470a-94e5-4ed5c1c7d353</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;sorry.. I had changed the buffer sizes since the time I attached the spis code.. here is the latest (it&amp;#39;s the same as before except buffer sizes and may be a print or two)..&lt;br /&gt;&lt;br /&gt;I will check the register like you suggested but I can clearly see handler getting called dozens of times (from prints)..&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;pasting the code here (inserting it using code tag doesn&amp;#39;t seem to work when I tried just now)..&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;/*&lt;br /&gt; * Copyright (c) 2020 Nordic Semiconductor ASA&lt;br /&gt; *&lt;br /&gt; * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic&lt;br /&gt; */&lt;/p&gt;
&lt;p&gt;#include &amp;lt;string.h&amp;gt;&lt;br /&gt;#include &amp;lt;zephyr.h&amp;gt;&lt;br /&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;#include &amp;lt;drivers/spi.h&amp;gt;&lt;br /&gt;#include &amp;lt;nrfx.h&amp;gt;&lt;br /&gt;#include &amp;lt;nrfx_uarte.h&amp;gt;&lt;br /&gt;#include &amp;quot;nrfx_spis.h&amp;quot;&lt;/p&gt;
&lt;p&gt;#define PIN_SCK 10&lt;br /&gt;#define PIN_MOSI 11&lt;br /&gt;#define PIN_MISO 12&lt;br /&gt;#define PIN_CSN 13&lt;br /&gt;#define SPIS_NR 3&lt;/p&gt;
&lt;p&gt;nrfx_spis_t spis_t = NRFX_SPIS_INSTANCE(SPIS_NR);&lt;br /&gt;nrfx_spis_config_t spis_config_t = NRFX_SPIS_DEFAULT_CONFIG(PIN_SCK,PIN_MOSI,PIN_MISO,PIN_CSN);&lt;/p&gt;
&lt;p&gt;uint8_t rx_buffer[] = &amp;quot;IFMMP GSPN BMJWFDPS!&amp;quot;;&lt;br /&gt;uint8_t tx_buffer[] = &amp;quot;Hello back AliveCor!&amp;quot;;&lt;/p&gt;
&lt;p&gt;void spis_event_handler_t(nrfx_spis_evt_t const *p_event, void *p_context){&lt;br /&gt; printk(&amp;quot;handler\n&amp;quot;);&lt;br /&gt; int err;&lt;br /&gt; switch(p_event-&amp;gt;evt_type){&lt;br /&gt; case NRFX_SPIS_XFER_DONE:&lt;br /&gt; printk(&amp;quot;received %s(%d) and sending %s(%d)\n&amp;quot;,rx_buffer, sizeof(rx_buffer),tx_buffer, sizeof(tx_buffer));&lt;br /&gt; err = nrfx_spis_buffers_set(&amp;amp;spis_t, tx_buffer, sizeof(tx_buffer), rx_buffer, sizeof(rx_buffer));&lt;br /&gt; if(err != NRFX_SUCCESS){&lt;br /&gt; printk(&amp;quot;Error with setting.\n&amp;quot;);&lt;br /&gt; }&lt;br /&gt; tx_buffer[0]++;&lt;br /&gt; break;&lt;br /&gt; case NRFX_SPIS_BUFFERS_SET_DONE:&lt;br /&gt; printk(&amp;quot;buffers set\n&amp;quot;);&lt;br /&gt; break;&lt;br /&gt; case NRFX_SPIS_EVT_TYPE_MAX:&lt;br /&gt; &lt;br /&gt; break;&lt;br /&gt; default:&lt;br /&gt; ;&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;static void manual_isr_setup()&lt;br /&gt;{&lt;br /&gt; //IRQ_DIRECT_CONNECT(SPIM3_SPIS3_TWIM3_TWIS3_UARTE3_IRQn, 0, nrfx_spis_3_irq_handler, 0);&lt;br /&gt; //irq_enable(SPIM3_SPIS3_TWIM3_TWIS3_UARTE3_IRQn);&lt;br /&gt; IRQ_DIRECT_CONNECT(UARTE3_SPIM3_SPIS3_TWIM3_TWIS3_IRQn, 0, nrfx_spis_3_irq_handler, 0);&lt;br /&gt; irq_enable(UARTE3_SPIM3_SPIS3_TWIM3_TWIS3_IRQn); &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;void init_spis(){&lt;br /&gt; int err;&lt;/p&gt;
&lt;p&gt;//change mode&lt;br /&gt; spis_config_t.mode = NRF_SPIS_MODE_3;&lt;br /&gt; err = nrfx_spis_init(&amp;amp;spis_t,&amp;amp;spis_config_t,spis_event_handler_t,NULL);&lt;br /&gt; if(err != NRFX_SUCCESS){&lt;br /&gt; printk(&amp;quot;nrfx_spis_init - Error. %x\n&amp;quot;,err);&lt;br /&gt; } else {&lt;br /&gt; printk(&amp;quot;SPIS started.\n&amp;quot;);&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;void spi_slave_test(void) {&lt;br /&gt; int err;&lt;br /&gt; init_spis();&lt;br /&gt; manual_isr_setup();&lt;/p&gt;
&lt;p&gt;printk(&amp;quot;rx_buffer %s(%d) and tx_buffer %s(%d)\n&amp;quot;,rx_buffer, sizeof(rx_buffer),tx_buffer, sizeof(tx_buffer));&lt;br /&gt; err = nrfx_spis_buffers_set(&amp;amp;spis_t, tx_buffer, sizeof(tx_buffer), rx_buffer, sizeof(rx_buffer));&lt;br /&gt; if(err != NRFX_SUCCESS){&lt;br /&gt; printk(&amp;quot;nrfx_spis_buffers_set - Error. %x\n&amp;quot;, err);&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;void main(void)&lt;br /&gt;{&lt;br /&gt; printk(&amp;quot;SPIS sample started \n\r&amp;quot;);&lt;br /&gt; spi_slave_test();&lt;br /&gt; while (1) {&lt;br /&gt; //printk(&amp;quot;alive \n&amp;quot;);&lt;br /&gt; //k_sleep(Z_TIMEOUT_TICKS(50000));&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284542?ContentTypeID=1</link><pubDate>Fri, 11 Dec 2020 13:22:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de89418c-13b2-48d4-8a4a-d5fad1b3c51c</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="sshenoy105"]you are a life saver sir.. thank you very much&lt;br /&gt;&lt;br /&gt;This works fine.. I can raise another ticket but I will try my luck here and I am sure i won&amp;#39;t be the only one who will thanking this ticket :-)[/quote]
&lt;p&gt;I&amp;#39;m glad to hear that it worked! Always happy to help out.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="sshenoy105"]For every time I send data from the master (I use&amp;nbsp;spi_transceive),&amp;nbsp; the handler&amp;nbsp;spis_event_handler_t in the slave gets called way too many times. You already have the slave code that I had attached.. any clue as to why that may happen ?[/quote]
&lt;p&gt;The slave code currently has set buffers of 2 byte (unless you have altered this from the original post), but the master sends a larger string (21 bytes inc. zero termination).&lt;/p&gt;
&lt;p&gt;If you peek into the NRF_SPIS1-&amp;gt;INTENSET register, you can see which events are interrupt-enabled:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/spis.html?cp=4_0_0_5_25_4_6#register.INTENSET"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf52840/spis.html?cp=4_0_0_5_25_4_6#register.INTENSET&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When I tested this, the content was 0x402, meaning EVENTS_ACQUIRED and EVENTS_END are interrupt enabled. You should then get two interrupts per transaction. However; if the slave doesn&amp;#39;t have enough buffer space, so it&amp;#39;ll only receive its max configured size, and the rest will be transferred back as a default overread character. You should set the size higher on your SPIS.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How many times does your spi slave give an interrupt? You should get two per SPI transaction.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind 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: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284410?ContentTypeID=1</link><pubDate>Thu, 10 Dec 2020 20:44:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ab4b45a-4bdb-47ef-a607-1efa13ba3f3a</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;you are a life saver sir.. thank you very much&lt;br /&gt;&lt;br /&gt;This works fine.. I can raise another ticket but I will try my luck here and I am sure i won&amp;#39;t be the only one who will thanking this ticket :-)&lt;br /&gt;I have a nrf5340 acting like a master and sending data to nrf9160 which is acting like a slave.. &lt;span&gt;the master is very simple (and loop back works as well)..&amp;nbsp;&lt;/span&gt;For every time I send data from the master (I use&amp;nbsp;spi_transceive),&amp;nbsp; the handler&amp;nbsp;spis_event_handler_t in the slave gets called way too many times. You already have the slave code that I had attached.. any clue as to why that may happen ?&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;sys/printk.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;
#include &amp;lt;nrfx.h&amp;gt;
#include &amp;lt;nrfx_uarte.h&amp;gt;

static const struct spi_config spi_cfg = {
	.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
		     SPI_MODE_CPOL | SPI_MODE_CPHA,
	.frequency = 800000,//4000000,
	.slave = 0,
};

struct device * spi_dev;

static void spi_init(void)
{
	const char* const spiName = &amp;quot;SPI_1&amp;quot;;
	spi_dev = device_get_binding(spiName);

	if (spi_dev == NULL) {
		printk(&amp;quot;Could not get %s device\n&amp;quot;, spiName);
		return;
	}
}

void spi_test_send(void)
{
	int err;
	static uint8_t tx_buffer[]=&amp;quot;Hello from Abcdefgh!&amp;quot;;
	static uint8_t rx_buffer[]=&amp;quot;IFMMP GSPN BCDEFGHI!&amp;quot;;

	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
	};

	err = spi_transceive(spi_dev, &amp;amp;spi_cfg, &amp;amp;tx, &amp;amp;rx);
	if (err) {
		printk(&amp;quot;SPI error: %d\n&amp;quot;, err);
	} else {
		/* Connect MISO to MOSI for loopback */
		printk(&amp;quot;TX sent: %s\n&amp;quot;, tx_buffer);
		printk(&amp;quot;RX recv: %s\n&amp;quot;, rx_buffer);
		tx_buffer[0]++;
	}	
}


void main(void)
{
	printk(&amp;quot;Hello sheshu - take 2 %s\n&amp;quot;, CONFIG_BOARD);
	spi_init();

	while (1) {
		spi_test_send();
		//k_sleep(1000);
                //printk(&amp;quot;alive \n&amp;quot;);
                k_sleep(Z_TIMEOUT_TICKS(50000));
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;proj.conf&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;CONFIG_SERIAL=y&lt;/p&gt;
&lt;p&gt;CONFIG_UART_INTERRUPT_DRIVEN=y&lt;/p&gt;
&lt;p&gt;CONFIG_LOG=y&lt;br /&gt;CONFIG_LOG_IMMEDIATE=y&lt;/p&gt;
&lt;p&gt;# SPI&lt;br /&gt;CONFIG_SPI=y&lt;br /&gt;CONFIG_SPI_1=y&lt;/p&gt;
&lt;p&gt;CONFIG_MAIN_STACK_SIZE=4096&lt;/p&gt;
&lt;p&gt;CONFIG_NRF5340_CPUAPP_ERRATUM19=y&lt;/p&gt;
&lt;p&gt;CONFIG_RESET_ON_FATAL_ERROR=n&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;overlay&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;amp;spi1 {&lt;br /&gt; compatible = &amp;quot;nordic,nrf-spim&amp;quot;;&lt;br /&gt; status = &amp;quot;okay&amp;quot;;&lt;br /&gt; mosi-pin = &amp;lt;4&amp;gt;;&lt;br /&gt; miso-pin = &amp;lt;10&amp;gt;; //&amp;lt;5&amp;gt;;&lt;br /&gt; sck-pin = &amp;lt;6&amp;gt;;&lt;br /&gt; csn-pin = &amp;lt;7&amp;gt;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;amp;i2c1 {&lt;br /&gt; status = &amp;quot;disabled&amp;quot;;&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;the entire project is also attached&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/hello_5F00_world2.zip"&gt;devzone.nordicsemi.com/.../hello_5F00_world2.zip&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284242?ContentTypeID=1</link><pubDate>Thu, 10 Dec 2020 08:27:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7b7dadf-9f48-4eb4-bd1e-44f006507723</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for providing the full project. This makes it&amp;nbsp;&lt;/p&gt;
[quote user=""]I am just confused to see that&lt;strong&gt;&amp;nbsp;p_cb-&amp;gt;state is set to&amp;nbsp;NRFX_DRV_STATE &lt;/strong&gt;for some reason&lt;br /&gt;m_cb[p_instance-&amp;gt;drv_inst_idx] has valid data... that array has ONLY ONE element (given only spi3 is available)&amp;nbsp; and&amp;nbsp;&lt;span&gt;drv_inst_idx=0;&lt;/span&gt;[/quote]
&lt;p&gt;&amp;nbsp;The problem is that the nrfx_spis and zephyr&amp;#39;s spi slave do not play well together, so you have to only have one of these enabled to be able to use the SPIS properly.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]It is clear that I a missing&amp;nbsp;some configuration.. I was told to make some spis related changes using the SES -&amp;gt;project-&amp;gt;configure nrf sdk project.. I tried to enable spis2 instance and spis3 driver and that made no difference.. I am sure you have some document in there somewhere in your ocean of documents explaining this but unfortunately I couldn&amp;#39;t find any details[/quote]
&lt;p&gt;&amp;nbsp;As your project is setup now, the zephyr spi driver will be initialized &amp;quot;post kernel&amp;quot; (see here: &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/spi/spi_nrfx_spis.c#L290-L297"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/spi/spi_nrfx_spis.c#L290-L297&lt;/a&gt;), and before main() is called. This means that the spis_nrfx_spis.c implementation will then claim the SPIS3 peripheral before you can via the nrfx_spis API in main.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The fix is to disable the zephyr SPI driver and enable the NRFX_SPIS configs:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# SPI
#CONFIG_SPI=y
## for slave only
#CONFIG_SPI_SLAVE=y
#CONFIG_SPI_3_OP_MODES=3

#commented these out as per some devzone discussions
#CONFIG_SPI_3=y
#CONFIG_SPI_NRFX=y
#CONFIG_SPI_3_NRF_SPIS=y #this gives an error while opening a project if uncomm&amp;gt;

CONFIG_NRFX_SPIS=y
CONFIG_NRFX_SPIS3=y

CONFIG_RESET_ON_FATAL_ERROR=n
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After these changes, the firmware should print this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*** Booting Zephyr OS build v2.4.0-ncs1  ***
SPIS sample started
SPIS started.
handler
buffers set
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you see if this is the case on your end as well?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind 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: issues with implementing SPI slave on nrf9160DK</title><link>https://devzone.nordicsemi.com/thread/284175?ContentTypeID=1</link><pubDate>Wed, 09 Dec 2020 17:26:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b42d165-6985-4e1f-a09b-bfc09c38d53c</guid><dc:creator>sshenoy105</dc:creator><description>&lt;p&gt;Corrections:&amp;nbsp;&lt;br /&gt;&lt;strong&gt;p_cb-&amp;gt;state is set to&amp;nbsp;NRFX_DRV_STATE_INITIALIZED&lt;br /&gt;&lt;span&gt;I tried to enable spis3 instance and spis3 driver&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>