<?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>nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39616/nrf52840-spis-semaphore-acquire-and-release</link><description>Hi All, 
 I am using the nRF52840, with SDK140 v15.0. I have configured the nRF52840 to be a SPI slave to a NXP processor. When I connect the logic analyzer I see signals on the SCK line and MOSI lines as well as the CS line going low. I also see the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 Mar 2021 15:07:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39616/nrf52840-spis-semaphore-acquire-and-release" /><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/297574?ContentTypeID=1</link><pubDate>Wed, 03 Mar 2021 15:07:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bbb753b7-e491-4384-912b-141903bcbcda</guid><dc:creator>Olly_OB</dc:creator><description>&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;I&amp;#39;ve managed to solve my issue with the ACQUIRE event, so I&amp;#39;ll post some information here in case it helps someone else in the future.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;strong&gt;Background&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;I was working on implementing SPIS functionality for the NRF52832 within Mbed OS. This involved working through the &amp;nbsp;&lt;code&gt;targets/&lt;/code&gt;.&lt;code&gt;../TARGET_MCU_NRF52832/spi_api.c&lt;/code&gt;&amp;nbsp;file&amp;nbsp;within Mbed and trying to add SPIS functionality around the existing SPI/SPIM functionality.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;The program would hang whenever I ran&amp;nbsp;&lt;code&gt;nrfx_spis_buffers_set()&lt;/code&gt;. Digging further down, I found that the program&amp;nbsp;would trigger the task to acquire the semaphore,&amp;nbsp;&lt;code&gt;nrf_spis_task_trigger&lt;/code&gt;&lt;code&gt;(p_spis,&amp;nbsp;NRF_SPIS_TASK_ACQUIRE)&lt;/code&gt;, however&amp;nbsp;the&amp;nbsp;&lt;code&gt;spis_irq_handler()&lt;/code&gt; would never be called.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;After too many days of investigation, I found that I had not&amp;nbsp;registered the interrupt handlers in the driver with the NVIC.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;Simply put, I should have called:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;NVIC_SetVector(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn,&amp;nbsp;(uint32_t)&amp;nbsp;SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler)&lt;/span&gt;&lt;/code&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;Before calling:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;code&gt;nrfx_spis_buffers_set()&lt;/code&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span style="font-family:arial, helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;br /&gt;I appreciate that this may be more of an Mbed OS issue, however there seems to have been a number of people that have experienced this issue, so I wanted to leave it here anyway, just in case others find it useful.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/296016?ContentTypeID=1</link><pubDate>Wed, 24 Feb 2021 12:36:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c73fba9-f9b6-4cd5-87b1-bb16b8fce377</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is not easy to see if this is the same issue as you are seeing or not. I suggest you create a new question where you explain the issue you are seeing in more detail in order to look at that specifically. (There you could refer to this thread.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/295927?ContentTypeID=1</link><pubDate>Tue, 23 Feb 2021 21:29:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ef1fe3b-bcee-4780-98df-5676c92d655a</guid><dc:creator>Olly_OB</dc:creator><description>&lt;p&gt;I know this is a long shot, but I&amp;#39;m experiencing the exact same issue, and it appears that a lot of people have also encountered this. Does anyone know of the solution?&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve gone through and confirmed that&amp;nbsp;&lt;span&gt;SPIS has been successfully configured&amp;nbsp;&lt;/span&gt;&lt;em&gt;before&lt;/em&gt;&lt;span&gt;&amp;nbsp;the CS line is being pulled low. However it appears that I&amp;#39;m unable to ACQUIRE the semaphore.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/199088?ContentTypeID=1</link><pubDate>Wed, 17 Jul 2019 22:57:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e60d3f3-d9c6-46e5-94fa-bc3eb66880d2</guid><dc:creator>Narayanan</dc:creator><description>&lt;p&gt;Any conclusion on this case? I am running into exactly same issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/176821?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 21:17:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4426597-0342-4aae-b080-0b4fa34a52fb</guid><dc:creator>donbosley</dc:creator><description>&lt;p&gt;Is there any chance or a hardware or resource conflict based on the SPI in use - I had different behavior result from using SPI1 vs using SPI 0 - in SPIS1 I never entered the handler (tried using a breakpoint in ozone as well as an NRF LOG). When I switched to 0, it entered handler. When I added code to refresh the buffer pointers in the event handler it started working as expected.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/166548?ContentTypeID=1</link><pubDate>Fri, 18 Jan 2019 15:41:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:941f5aef-2029-4a09-93a1-fdd1dc8f46b7</guid><dc:creator>Tech</dc:creator><description>&lt;p&gt;Hi All,&lt;/p&gt;
&lt;p&gt;I am using the nRF52840 with SDK140 v15.2. I have configured the nRF52840 to be a SPI slave as you did. I am experiencing the same problem you had. Did you solved the problem? Can you tell me what you did?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you in advance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/154009?ContentTypeID=1</link><pubDate>Tue, 23 Oct 2018 08:55:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:635db0d9-3be5-4e12-acef-02677b490ce8</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Is the code getting stuck at the very first transmission?&lt;/p&gt;
&lt;p&gt;Can you confirm that the SPIS has been successfully configured &lt;em&gt;before&lt;/em&gt; the CS line is being pulled low?&lt;/p&gt;
&lt;p&gt;If you debug your application (using a debugger and not printfs), where exactly does your code end up?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/153688?ContentTypeID=1</link><pubDate>Fri, 19 Oct 2018 16:09:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76bd01d9-9baf-43e5-80da-ecf271d115c0</guid><dc:creator>Saili</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The &amp;quot;Enable&amp;quot; trace in the scope capture above is the CS line, which is low in the trace. I posted a zoomed in version so that the data sent on the MOSI line was visible/ readable. Here is a zoomed out version showing the CS line (Enable trace) going low before the start of transaction and going high after the end of SPI transaction. Attached is the zoomed out trace.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screen-Shot-2018_2D00_10_2D00_19-at-8.56.40-AM.png" /&gt;&lt;/p&gt;
&lt;p&gt;The code does not crash but just is waiting for ever. And yes, like you pointed out there is not much that can go wrong with the function that is why I am stumped. I am also checking the error codes but I might be missing something, hence I have attached the code. &lt;pre class="ui-code" data-mode="text"&gt;static void _run_spi_slave_loopback_test(void)
{
    uint32_t nrf_err = NRF_SUCCESS;

    LOG_INFO(&amp;quot;Starting SPIS demo, press button 3 to exit...&amp;quot;);

    if (!_spi_slave_initialized)
    {
        static const nrfx_gpiote_out_config_t slave_pin_config = NRFX_GPIOTE_CONFIG_OUT_SIMPLE(true);

        snprintf((char *)_m_tx_buf, 127, &amp;quot;%s&amp;quot;, TEST_STRING);

        if (nrfx_gpiote_out_init(PIN_MAP_SPIS_SLAVE_READY_PIN, &amp;amp;slave_pin_config) != (ret_code_t) NRF_SUCCESS)
        {
            LOG_ERROR(&amp;quot;Failed to initialize SRDY pin&amp;quot;);
            goto rsslt_exit;
        }

        // initialize the SPI slave driver
        nrfx_spis_config_t spis_config = { .sck_pin = PIN_MAP_SPIS1_CONFIG_SCK_PIN,
                                              .mosi_pin = PIN_MAP_SPIS1_CONFIG_MOSI_PIN,
                                              .miso_pin = PIN_MAP_SPIS1_CONFIG_MISO_PIN,
                                              .csn_pin = PIN_MAP_SPIS1_CONFIG_PCS_PIN,
                                              .miso_drive = NRFX_SPIS_DEFAULT_MISO_DRIVE,
                                              .csn_pullup = NRFX_SPIS_DEFAULT_CSN_PULLUP,
                                              .orc = SPIS_DEFAULT_ORC,
                                              .def = SPIS_DEFAULT_DEF,
                                              .mode = NRF_SPIS_MODE_0,
                                              .bit_order = NRF_SPIS_BIT_ORDER_MSB_FIRST,
                                              .irq_priority = PIN_MAP_SPIS1_CONFIG_IRQ_PRIORITY };

        nrf_err = nrfx_spis_init(&amp;amp;_spis, &amp;amp;spis_config, _spis_event_handler, NULL);
        if (nrf_err != NRF_SUCCESS)
        {
            LOG_ERROR(&amp;quot;Failed to initialize SPIS&amp;quot;);
            goto rsslt_exit;
        }
        _spi_slave_initialized = true;
    }

    while (1)
    {
        memset(_m_rx_buf, 0, _m_length);
        _spis_xfer_done = false;

        nrf_err = nrfx_spis_buffers_set(&amp;amp;_spis, _m_tx_buf, _m_length, _m_rx_buf, _m_length);
        if (nrf_err != NRF_SUCCESS)
        {
            LOG_ERROR(&amp;quot;Failed to set SPIS buffers&amp;quot;);
            goto rsslt_exit;
        }

        while (!_spis_xfer_done)
        {
            if (bsp_button_pressed(BSP_BUTTON_3))
            {
                LOG_INFO(&amp;quot;Button 3 pressed, stopping demo&amp;quot;);
                goto rsslt_exit;
            }

            nrf_delay_us(10);
        }

        if (_spis_xfer_done)
        {
            LOG_INFO(&amp;quot;Transfer completed. Received: %s&amp;quot;, _m_rx_buf);
            LOG_INFO(&amp;quot;Toggling SRDY pin for 1ms as a test.&amp;quot;);
            nrfx_gpiote_out_clear(PIN_MAP_SPIS_SLAVE_READY_PIN);
            nrf_delay_ms(1);
            nrfx_gpiote_out_set(PIN_MAP_SPIS_SLAVE_READY_PIN);
        }
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 SPIS semaphore acquire and release</title><link>https://devzone.nordicsemi.com/thread/153631?ContentTypeID=1</link><pubDate>Fri, 19 Oct 2018 12:14:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4f5f7fc-5604-4b92-9e0f-2ccd38114f1b</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;You write that you can see the CS&amp;nbsp;line goes low, but I don&amp;#39;t see it in the logic trace. When does it happen? Is it possible that your problem is related to &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/18107/spis-without-cs/"&gt;this&lt;/a&gt;?&lt;span&gt;&amp;nbsp;You will need to pull the CS pin low after SPIS is initialized in order to aquire the semaphore.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Furthermore, by &amp;quot;&lt;span&gt;gets stuck at&amp;nbsp;&lt;/span&gt;&lt;span&gt;nrf_spis_task_trigger&amp;quot; I assume you mean that the code is &amp;quot;stuck&amp;quot; waiting for the semaphore and not actually crashing inside that function? There doesn&amp;#39;t seem to be much that can go wrong inside it:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;__STATIC_INLINE void nrf_spis_task_trigger(NRF_SPIS_Type * p_reg,
                                           nrf_spis_task_t spis_task)
{
    *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)spis_task)) = 0x1UL;
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If neither of this is helping:&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span&gt;Are you checking the return&amp;nbsp;code of all the functions in your code?&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;Can you upload your code?&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>