<?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>Trouble with Zephyr SPI slave</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80139/trouble-with-zephyr-spi-slave</link><description>Hi, 
 I&amp;#39;ve got a two-processor board (i.e. another processor in addition to the two-core nrf5340) where the other processor is sending data to my nrf5340 via SPI. The Nordic is the SPI slave. 
 *Oh, I&amp;#39;m currently using SDK version 1.5.1. I tried upgrading</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 04 Oct 2021 17:46:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80139/trouble-with-zephyr-spi-slave" /><item><title>RE: Trouble with Zephyr SPI slave</title><link>https://devzone.nordicsemi.com/thread/332428?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 17:46:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2aa2ba39-ba32-4104-ad50-9e4de9dae0b2</guid><dc:creator>Jeff4BLE</dc:creator><description>&lt;h1 class="title" id="mcetoc_1fh66g3ft0"&gt;&lt;span style="font-size:75%;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;Additional NCS SPI Reference material&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/peripherals/posts/adding-a-peripheral-to-an-ncs-zephyr-project"&gt;Adding a Peripheral to an NCS Zephyr project&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble with Zephyr SPI slave</title><link>https://devzone.nordicsemi.com/thread/332426?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 17:21:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de83e9c3-fc7b-4c27-ae74-74eaacb5ac06</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;Well now it&amp;#39;s working and I&amp;#39;m not certain what I did to make it so. I did upgrade to the 1.7.0 SDK. Anyway here&amp;#39;s the code now in case anyone else is trying to get the nrfx_spis driver going.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
//== Includes ================================================================

#include &amp;lt;nrfx.h&amp;gt;
#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;drivers/spi.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;spi_comms.h&amp;quot;
#include &amp;lt;nrfx_spis.h&amp;gt;
#include &amp;lt;logging/log.h&amp;gt;

//== Definitions and Types ===================================================
#define LOG_MODULE_NAME peripheral_SPI
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

#define GPIO_PORT_1_OFFSET 32

#define PIN_SCK            12
#define PIN_MOSI           22
#define PIN_MISO           20
#define PIN_CSN            GPIO_PORT_1_OFFSET + 2

#define SPIS_NR            0     // Using SPI0

#define SPI_BUFFER_SIZE    255

//== Global Variables ========================================================
nrfx_spis_t spi_slave_instance = NRFX_SPIS_INSTANCE(SPIS_NR);

nrfx_spis_config_t spis_config = NRFX_SPIS_DEFAULT_CONFIG(PIN_SCK,PIN_MOSI,PIN_MISO,PIN_CSN);

uint8_t rx_buffer[SPI_BUFFER_SIZE];
uint8_t tx_buffer[SPI_BUFFER_SIZE];

//== Function prototypes =====================================================
void spis_event_handler(nrfx_spis_evt_t const *p_event, void *p_context);

//============================================================================

//----------------------------------------------------------------------------
// Name  : spi_comms_init
// Desc  : Configure the SPI slave device using the nrfx_spis driver
// Ins   : none
// Outs  : none
//----------------------------------------------------------------------------
void spi_comms_init(void)
{
   int err;

   nrf_spis_disable(spi_slave_instance.p_reg);

   err = nrfx_spis_init(&amp;amp;spi_slave_instance, &amp;amp;spis_config, spis_event_handler, NULL);
   if(err != NRFX_SUCCESS)
   {
      LOG_WRN(&amp;quot;Error with init.\n&amp;quot;);
   } else 
   {
      LOG_WRN(&amp;quot;SPIS started.\n&amp;quot;);
   }
 
   err = nrfx_spis_buffers_set(&amp;amp;spi_slave_instance, tx_buffer, sizeof(tx_buffer), rx_buffer, sizeof(rx_buffer));
   if(err != NRFX_SUCCESS)
   {
       LOG_WRN(&amp;quot;Error with setting.\n&amp;quot;);
   }

   IRQ_DIRECT_CONNECT(SPIM0_SPIS0_TWIM0_TWIS0_UARTE0_IRQn, 0, nrfx_spis_0_irq_handler, 0);
   irq_enable(SPIM0_SPIS0_TWIM0_TWIS0_UARTE0_IRQn);
}

//----------------------------------------------------------------------------
// Name  : spis_event_handler
// Desc  : Callback function from the SPI driver
// Ins   : Event pointer and an unused context pointer
// Outs  : none
//----------------------------------------------------------------------------
void spis_event_handler(nrfx_spis_evt_t const *p_event, void *p_context)
{
   int err;
   switch(p_event-&amp;gt;evt_type)
   {
      case NRFX_SPIS_XFER_DONE:
         if (p_event-&amp;gt;rx_amount &amp;gt; 0)
         {
            LOG_INF(&amp;quot;received 0x%02x 0x%02x 0x%02x 0x%02x...\n&amp;quot;, rx_buffer[0], rx_buffer[1], rx_buffer[2], rx_buffer[3]);
         }
            
          //LOG_INF(&amp;quot;Rx bytes: %u\n&amp;quot;, p_event-&amp;gt;rx_amount);
          err = nrfx_spis_buffers_set(&amp;amp;spi_slave_instance, tx_buffer, sizeof(tx_buffer), rx_buffer, sizeof(rx_buffer));
          if(err != NRFX_SUCCESS)
          {
             LOG_WRN(&amp;quot;Error with setting.\n&amp;quot;);
          }
          break;

      case NRFX_SPIS_BUFFERS_SET_DONE:
         //LOG_WRN(&amp;quot;buffers set\n&amp;quot;);
         break;

      case NRFX_SPIS_EVT_TYPE_MAX:        
         break;
      
      default:
         ;
   }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble with Zephyr SPI slave</title><link>https://devzone.nordicsemi.com/thread/332255?ContentTypeID=1</link><pubDate>Mon, 04 Oct 2021 08:22:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:964d9292-6650-4f74-8d73-273134d69779</guid><dc:creator>Sigurd</dc:creator><description>[quote user="Glen M"]So both this example and the other one I found have the slave actively performing transfers in order to receive things. I was expecting that since my device is a slave that all I had to do was configure the peripheral and then wait for an interrupt to tell me that data had arrived. Is that not the case? Do I have to actively poll for received data?[/quote]
&lt;p&gt;&lt;span&gt;The SPIS handling uses a mutex in the zephyr port &amp;quot;spi_nrfx_spis.c&amp;quot;, so even if it looks to be a blocking/polling implementation, it is actually event driven underneath.&lt;/span&gt;&lt;/p&gt;
[quote user="Glen M"]Is there an appnote or something on how the SPI slave peripheral works? I can&amp;#39;t find any real documentation.[/quote]
&lt;p&gt;&lt;span&gt;I&amp;#39;m not aware of any appnote here, but we have the PS:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf5340%2Fspis.html"&gt;https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf5340%2Fspis.html&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble with Zephyr SPI slave</title><link>https://devzone.nordicsemi.com/thread/332212?ContentTypeID=1</link><pubDate>Fri, 01 Oct 2021 23:58:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8331b400-5bd3-4a6d-ba97-b5e7e7108353</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;So both this example and the other one I found have the slave actively performing transfers in order to receive things. I was expecting that since my device is a slave that all I had to do was configure the peripheral and then wait for an interrupt to tell me that data had arrived. Is that not the case? Do I have to actively poll for received data?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, I found a function called&amp;nbsp;&lt;span&gt;nrf_spis_subscribe_set in the driver. Is that something I need to use? The InfoCenter doesn&amp;#39;t tell me anything more about it than what I already guessed from the function name.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is there an appnote or something on how the SPI slave peripheral works? I can&amp;#39;t find any real documentation.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble with Zephyr SPI slave</title><link>https://devzone.nordicsemi.com/thread/332202?ContentTypeID=1</link><pubDate>Fri, 01 Oct 2021 18:54:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cc51654-0dba-4a7a-9fd7-5e1a553134db</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;Well I still haven&amp;#39;t gotten it working yet but I did solve the problem with the pin assignments. You can&amp;#39;t change those once the peripheral is enabled, and I guess it was starting out enabled - so I added a call to&amp;nbsp;nrf_spis_disable before my init call.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Trouble with Zephyr SPI slave</title><link>https://devzone.nordicsemi.com/thread/331968?ContentTypeID=1</link><pubDate>Thu, 30 Sep 2021 14:00:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36369ac1-5e52-42fb-bd42-f01c4c92d3a7</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;A colleague of mine created a SPIS sample some months ago,&amp;nbsp; it might be useful for you to take a look at&amp;nbsp;that sample and see how SPIS is handled there.&lt;/p&gt;
&lt;p&gt;Attachment: &lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/spis_5F00_thread_5F00_test.rar"&gt;devzone.nordicsemi.com/.../spis_5F00_thread_5F00_test.rar&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>