<?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>SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59596/spis-not-working-with-s140-softdevice-on-nrf52840</link><description>Hello, 
 we are developing a firmware for the nRF52840 which requires the use of Bluetooth and the SPIS (SPI Slave) functionality. 
 We are using S140 &amp;amp; SDK 16. 
 
 We encounter the following problem: 
 During init, we configure a 2 byte TX buffer for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Mar 2020 15:35:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59596/spis-not-working-with-s140-softdevice-on-nrf52840" /><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242503?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 15:35:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5aa9c3bc-ed18-4ff2-b85c-6c1a544223be</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thank you for the update! &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242495?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 15:06:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3afdfe7b-2c56-40d7-8c19-2b6f0b242cf8</guid><dc:creator>Maik</dc:creator><description>&lt;p&gt;Found the problem:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static nrfx_spis_t spi_instance = NRFX_SPIS_INSTANCE( 0 ); // &amp;lt;- declare here

static void*   spi_defaultContext;
static uint8_t spi_defaultTxBuffer[2];
static uint8_t spi_defaultRxBuffer[2];

void spi_init( void )
{
  // snip

  nrfx_spis_buffers_set( spi_instance, spi_defaultTxBuffer, 2, spi_defaultRxBuffer.controlSequence, 2 );
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We initialized&amp;nbsp;p_instance in spi_init() and pointed the static pointer spi_instance to it.&lt;/p&gt;
&lt;p&gt;--&amp;gt; pointer to a stack location that gets overwritten.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you very much for the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242470?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 14:18:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05f34220-58e8-482d-a738-253681b4a2b2</guid><dc:creator>Maik</dc:creator><description>&lt;p&gt;We updated the handler as follows:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void spi_evt_handler( nrfx_spis_evt_t const* p_event, void* p_contex )
{
  NRF_LOG_DEBUG( &amp;quot;Event: %d&amp;quot;, p_event-&amp;gt;evt_type);
  if( p_event-&amp;gt;evt_type == NRFX_SPIS_BUFFERS_SET_DONE ) 
  {
    NRF_LOG_DEBUG( &amp;quot;Buffer set&amp;quot;);
  }
  else if( ( p_event-&amp;gt;evt_type == NRFX_SPIS_XFER_DONE ) )
  {
    NRF_LOG_DEBUG( &amp;quot;Transmission Done: %d, %d&amp;quot;, p_event-&amp;gt;rx_amount, p_event-&amp;gt;tx_amount);
    APP_ERROR_CHECK( nrfx_spis_buffers_set( spi_instance, spi_defaultTxBuffer, 2, NULL, 0 ) );
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The result is the same.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1585578016303v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;We also added some logging to the event handler.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;debug&amp;gt; app: Event: 0
&amp;lt;debug&amp;gt; app: Buffer set


// snip

&amp;lt;debug&amp;gt; app: Event: 1
&amp;lt;debug&amp;gt; app: Transmission Done: 2, 2&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;We only get one event of type NRFX_SPIS_BUFFERS_SET_DONE and one of type NRFX_SPIS_XFER_DONE. Nothing for the second transmission.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242436?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 13:14:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a6a393f-6b4b-4995-8e37-18af8ce6d7ed</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks. Looks like the TX buffer is set only once in the code you provided? It must be updated after every completed transaction by calling nrfx_spis_buffers_set(). &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242414?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 12:48:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61cf78a6-5d69-4843-a129-6a49b659fb31</guid><dc:creator>Maik</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;we also tried 100 uS and are getting the same result.&lt;/p&gt;
&lt;p&gt;I hope the following snippets are enough.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static nrfx_spis_t const* spi_instance;

static void*   spi_defaultContext;
static uint8_t spi_defaultTxBuffer[2];
static uint8_t spi_defaultRxBuffer[2];


void spi_init( void )
{
  nrfx_spis_config_t p_config   = NRFX_SPIS_DEFAULT_CONFIG;
  nrfx_spis_t        p_instance = NRFX_SPIS_INSTANCE( 0 );
  spi_instance                  = &amp;amp;p_instance;
  p_config.miso_pin             = BLE_MISO_PIN;
  p_config.mosi_pin             = BLE_MOSI_PIN;
  p_config.sck_pin              = BLE_SCLK_PIN;
  p_config.csn_pin              = BLE_CS_PIN;
  p_config.def                  = 0xAA;
  p_config.orc                  = 0xBB;
  p_config.mode                 = NRF_SPIS_MODE_0;


  nrfx_spis_init( spi_instance, &amp;amp;p_config, (nrfx_spis_event_handler_t)spi_evt_handler, spi_defaultContext );

  NRF_POWER-&amp;gt;TASKS_CONSTLAT = 1;

  spi_defaultRxBuffer[0] = 0x00;
  spi_defaultRxBuffer[1] = 0x00;

  spi_defaultTxBuffer[0] = 0xDE;
  spi_defaultTxBuffer[1] = 0xAD;

  nrfx_spis_buffers_set( spi_instance, spi_defaultTxBuffer, 2, spi_defaultRxBuffer.controlSequence, 2 );
}

static void spi_evt_handler( nrfx_spis_evt_t const* p_event, void* p_contex )
{
// Empty
}


int main( void )
{
  log_init( );
  timers_init( );
  power_management_init( );
  spi_init( );
  ble_stack_init_( );
  
  //...

  // Enter main loop.
  for( ;; )
  {
    if( NRF_LOG_PROCESS( ) == false )
    {
      nrf_pwr_mgmt_run( );
    }
  }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242379?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 11:33:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7e77894-c02e-450e-a172-326b3a7c0813</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;2uS would still be marginal if you were in LP mode. Could you try 10 us so we can exclude CS timing as a possible cause? This would give the SPIS plenty of time to acquire the semaphore. Also, could you post some code snippets of your SPIS implementation?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242322?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 08:55:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff6fdaa0-3cd4-4839-9b06-72ca146b736c</guid><dc:creator>Maik</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;We have the constant latency mode enabled.&lt;br /&gt;The chipselect is done by the hardware, but we alternatively tried setting the spi-clock to 1 kHz, that should give plenty of time.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1585558496043v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;As you can see in the screenshot, the SPIS is still writing DEF (0xAA in our case).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Edit: We added a delay ( &amp;gt; 2 us) between CS low and the first clock.&lt;br /&gt;&lt;br /&gt;In the following screenshot you can see the first transfer, which is working fine&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1585564559619v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;The next screenshot shows the second transfer, which is sending out DEF (0xAA)&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1585564634033v2.png" alt=" " /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As far as our understanding goes, DEF is sent when the SPIS can&amp;#39;t acquire the semaphore.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPIS not working with S140 softdevice on nRF52840</title><link>https://devzone.nordicsemi.com/thread/242111?ContentTypeID=1</link><pubDate>Fri, 27 Mar 2020 13:36:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f97d03a2-50dc-499f-af50-008d91bf98db</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The SPIS requires a bit more time to wake-up from low power System ON mode because it needs to wait for the HF clock to ramp up. This is why the SPIS example enables constant latency mode on startup:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Enable the constant latency sub power mode to minimize the time it takes&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // for the SPIS peripheral to become active after the CSN line is asserted&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // (when the CPU is in sleep mode).&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NRF_POWER-&amp;gt;TASKS_CONSTLAT = 1;&lt;/p&gt;
&lt;p&gt;Is it possible to assert the CSN line a bit earlier in your case so the slave gets more time to wake-up? It will probably be the most optimal solution in terms of power consumption. The constant latency mode would increase the base current from a few uA to about 500 uA.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>