<?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 read without debugger</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22964/spi-slave-read-without-debugger</link><description>I am using nRF52840 DK as a SPI slave with an external MCU configured as SPI master. The SPI clock frequency is set to 1 MHz. I am using the following pins for SPI: 
 P0.29 - SPIS_CS_PIN
P0.28 - SPIS_MISO_PIN
P0.4 - SPIS_MOSI_PIN
P0.3 - SPIS_SCK_PIN</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Jul 2017 22:14:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22964/spi-slave-read-without-debugger" /><item><title>RE: SPI slave read without debugger</title><link>https://devzone.nordicsemi.com/thread/90351?ContentTypeID=1</link><pubDate>Tue, 11 Jul 2017 22:14:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b3938ec-6325-4cbf-917d-2a1ca9e07b91</guid><dc:creator>KV</dc:creator><description>&lt;p&gt;I was able to resolve this issue by following the suggestion in this &lt;a href="https://devzone.nordicsemi.com/question/23123/when-is-the-best-time-for-acquire-the-semaphore-spis-nrf51822/"&gt;post&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave read without debugger</title><link>https://devzone.nordicsemi.com/thread/90348?ContentTypeID=1</link><pubDate>Fri, 30 Jun 2017 12:48:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a94c6130-a596-4138-a360-bd33636ff207</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;To answer your question about placement of constant latency configuration: the reason why you get an error when placing it right before the while-loop in main is that you have enabled softdevice at this point. The softdevice &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.sds/dita/softdevices/s130/sd_resource_reqs/hw_block_interrupt_vector.html?cp=2_3_0_0_6_0"&gt;restricts access to some peripherals&lt;/a&gt;, including the POWER peripheral. The peripherals can only be accessed through softdevice-safe APIs. To configure constant latency mode with softdevice enabled, you can call &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v5.0.0/group___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html#ga5bb23d3ce98ba3afa1c3fa2b06d49491"&gt;&lt;code&gt;	sd_power_mode_set(NRF_POWER_MODE_CONSTLAT)&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave read without debugger</title><link>https://devzone.nordicsemi.com/thread/90353?ContentTypeID=1</link><pubDate>Fri, 30 Jun 2017 09:39:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:677edd7c-cc4e-46fa-9523-131ecbba757d</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;You can configure the chip to wakeup from GPIO. Put the device in sleep mode (system on, constant latency), and use GPIOTE to set a GPIO on wakeup. Measure the time from wakeup GPIO is triggered until the other GPIO is set by GPIOTE.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave read without debugger</title><link>https://devzone.nordicsemi.com/thread/90347?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2017 14:35:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13bdd804-4bfb-4e26-a17d-8f8766a41c06</guid><dc:creator>KV</dc:creator><description>&lt;p&gt;The SPI master is another MCU (MSP430FR5989). How do I measure the wakeup time for nRF52840?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave read without debugger</title><link>https://devzone.nordicsemi.com/thread/90352?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2017 12:45:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b92dd163-2d0b-40d7-b2d5-37bc0e325a6a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;What device is the SPI master? Does it specify any required wakeup time for the slave device? Have you tried measuring the wakeup time of the nRF52840 device when configuring contant latency mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave read without debugger</title><link>https://devzone.nordicsemi.com/thread/90350?ContentTypeID=1</link><pubDate>Tue, 27 Jun 2017 15:13:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a5aaae7-98e2-4853-b27a-5db5c9bda0eb</guid><dc:creator>KV</dc:creator><description>&lt;p&gt;Yes. I configured it in the constant latency mode by using NRF_POWER-&amp;gt;TASKS_CONSTLAT = 1 as the very first thing in the main. It did not make any difference.&lt;/p&gt;
&lt;p&gt;Also, I tried putting this just before entering the while(1) loop in the main. In this case, I did not even get a BLE connection. Not sure why this happens?&lt;/p&gt;
&lt;p&gt;Also, I commented out the sd_app_evt_wait inside the while(1) loop (i.e no low power mode). In this case SPI communication is normal and there are no issues when the debugger is not attached to the target.&lt;/p&gt;
&lt;p&gt;My main function is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{
    uint32_t ticks;

    // Enable the constant latency sub power mode to minimize the time it takes
    // for the SPIS peripheral to become active after the CSN line is asserted
    // (when the CPU is in sleep mode).
    NRF_POWER-&amp;gt;TASKS_CONSTLAT = 1;

    nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0,8)); //nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(0,30));


    nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;

    spis_config.csn_pin               = 6;//29;//APP_SPIS_CS_PIN;
    spis_config.miso_pin              = 22; //28;//APP_SPIS_MISO_PIN;
    spis_config.mosi_pin              = 20;//4;//APP_SPIS_MOSI_PIN;   15
    spis_config.sck_pin               = 24;//3;//APP_SPIS_SCK_PIN;

    APP_ERROR_CHECK(nrf_drv_spis_init(&amp;amp;spis, &amp;amp;spis_config, spis_event_handler));

    timer_init();
    ble_stack_init();
    gap_params_init();
    conn_params_init();
    gatt_init();
    advertising_data_set();
    server_init();
    client_init();
    gatt_mtu_set(m_test_params.att_mtu);
    data_len_ext_set(m_test_params.data_len_ext_enabled);
    conn_evt_len_ext_set(m_test_params.conn_evt_len_ext_enabled);
    preferred_phy_set(m_test_params.rxtx_phy);
    tx_power_set();

    advertising_start();

    for (;;)
    {
        wait_for_event();

        if(data_rdy)
        {
            // check if data is received over BLE
            data_rdy = false;
            //memset(m_rx_buf, 0, sizeof(m_rx_buf));
            spis_xfer_done = false;
            spis_xfer_timeout = false;
            ticks = nrf_drv_timer_ms_to_ticks(&amp;amp;TIMER_SPI, SPI_XFER_TIMEOUT_MS);   // 100 millisec timeout
            nrf_drv_timer_extended_compare(&amp;amp;TIMER_SPI, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
            nrf_drv_timer_enable(&amp;amp;TIMER_SPI);

            // respond to master with number of bytes received over BLE
            bytes_avail = m_tx_len;
            APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&amp;amp;spis,
                                                     &amp;amp;bytes_avail,
                                                     1,
                                                     m_rx_buf,
                                                     1));

            //SET_TEST_POINT(31);
            while (!spis_xfer_done &amp;amp;&amp;amp; !spis_xfer_timeout)
            {
                wait_for_event(); //__WFE();
            }

            if(  spis_xfer_done )
            {
                // respond to master with the actual bytes received over BLE (send TLV commmand)
                spis_xfer_done = false;
                spis_xfer_timeout = false;
                ticks = nrf_drv_timer_ms_to_ticks(&amp;amp;TIMER_SPI, SPI_XFER_TIMEOUT_MS);   // 100 millisec timeout
                nrf_drv_timer_extended_compare(&amp;amp;TIMER_SPI, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
                nrf_drv_timer_enable(&amp;amp;TIMER_SPI);

                APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&amp;amp;spis,
                                                         m_tx_buf,
                                                         m_tx_len,
                                                         m_rx_buf,
                                                         m_tx_len));

                //SET_TEST_POINT(31);
                while (!spis_xfer_done &amp;amp;&amp;amp; !spis_xfer_timeout)
                {
                   wait_for_event(); // __WFE();
                }

                if( spis_xfer_done )
                {
                    // read the response bytes from the master (receive TLV response)
                    spis_xfer_done = false;
                    spis_xfer_timeout = false;
                    ticks = nrf_drv_timer_ms_to_ticks(&amp;amp;TIMER_SPI, SPI_XFER_TIMEOUT_MS);   // 100 millisec timeout
                    nrf_drv_timer_extended_compare(&amp;amp;TIMER_SPI, NRF_TIMER_CC_CHANNEL0, ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
                    nrf_drv_timer_enable(&amp;amp;TIMER_SPI);
                    APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&amp;amp;spis,
                                                             m_tx_buf,// dummy send
                                                             m_tx_len,
                                                             m_rx_buf,
                                                             255));  // just read max possible

                    //SET_TEST_POINT(31);
                    while (!spis_xfer_done &amp;amp;&amp;amp; !spis_xfer_timeout)
                    {
                        wait_for_event(); //__WFE();
                    }
                }
            }

            nrf_gpio_pin_write(NRF_GPIO_PIN_MAP(0,8), 0); //nrf_gpio_pin_write(NRF_GPIO_PIN_MAP(0,30), 0); // clear the data ready line

            if(spis_xfer_done &amp;amp;&amp;amp; (m_amts.notif_pkt_sz &amp;gt; 0) )
            {
                // send if SPI transfer is success, do not send anything if timed out
                nrf_ble_amts_notif_spam(m_rx_buf, &amp;amp;m_amts);
                m_amts.notif_pkt_sz = 0;
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;My wait_for_event function is:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    static void wait_for_event(void)

{
    uint32_t  err_code;

    err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI slave read without debugger</title><link>https://devzone.nordicsemi.com/thread/90349?ContentTypeID=1</link><pubDate>Thu, 22 Jun 2017 07:59:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:156d0c0a-78be-475e-86c4-a52302b9d279</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Have you configured the chip in &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52840.ps/power.html?cp=2_0_0_15_3_0#unique_1763102267"&gt;constant latency system on mode&lt;/a&gt;? See &lt;a href="https://devzone.nordicsemi.com/question/91596/interrupt-latency-when-running-wfiwfe/?answer=91651#post-id-91651"&gt;this answer&lt;/a&gt; for more details about wakeup times from sleep mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>