<?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>BLE and GPIOTE interrupt problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/103442/ble-and-gpiote-interrupt-problem</link><description>Hi! 
 This is my setup: 
 - a dongle nrf52840 
 - 2 boards nrf52 DK (with a nrf52832 on them) 
 I&amp;#39;m trying to implement this. 
 I want to send a &amp;quot;START&amp;quot; command from the dongle to the &amp;quot;Board A&amp;quot;. The board A, once received the command, has to send over</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 11 Sep 2023 05:12:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/103442/ble-and-gpiote-interrupt-problem" /><item><title>RE: BLE and GPIOTE interrupt problem</title><link>https://devzone.nordicsemi.com/thread/445278?ContentTypeID=1</link><pubDate>Mon, 11 Sep 2023 05:12:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bbf8e5aa-5b30-4571-839a-add184a97bad</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;It is hard for me to say where the bottleneck is Federico.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;When you send 0x00CC from board A to board B and you can see on the logic analyzer or oscilloscope that your message is transmitted on the pins but board A did not process it. Then most likely there is something that is executing on board A that is masking the SPI driver.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Start both boards in debug mode and just before sending 0X00CC from board A, set a breakpoint in board B SPI callback handler. When you send 0x00CC then this callback should have been called. But the issue is that it isn&amp;#39;t called. So at this instance, pause the debugger to see what context is being executed (top function of the function call stack) and find out the priority in which it is being executed and compare it with SPI driver priority. I am basing all this assuming that you have actually transmitted the byte from BoardA but BoardB isn&amp;#39;t receiving/processing it for some reason.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and GPIOTE interrupt problem</title><link>https://devzone.nordicsemi.com/thread/444970?ContentTypeID=1</link><pubDate>Thu, 07 Sep 2023 13:55:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:583d5b17-f747-4ae6-bcfe-9fa13e67b92f</guid><dc:creator>FedericoDeSario</dc:creator><description>&lt;p&gt;When i send 0x00CC from boardA on BoardB seems that i don&amp;#39;t receive nothing.&lt;br /&gt;But if I try a lot of times in a little interval I can read on the log of board A that the command 0x00CC has been sended and board A has received 0xFFFF. This is strange becouse the tx_buffer of the SPI on board B is initialized with the word &amp;quot;OK&amp;quot; so it should be always 0x4F4B. And infact it is always&amp;nbsp;&lt;span&gt;0x&lt;/span&gt;&lt;span&gt;4F4B but not when I send the stop command.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Can the problem be&amp;nbsp;this function here?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&amp;amp;spis, m_tx_buf, m_length, m_rx_buf, m_length));&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I was thinking that probably, when I send the STOP command the buffers of the SPI of board B are not ready to receive data, due to the interrupt that has sended a freme a bit before.&lt;br /&gt;&lt;br /&gt;If this is the problem, how can i solve it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and GPIOTE interrupt problem</title><link>https://devzone.nordicsemi.com/thread/444616?ContentTypeID=1</link><pubDate>Wed, 06 Sep 2023 06:16:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57f8db9c-0c75-4a99-8424-2092bde91609</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="FedericoDeSario"]but it seems that che frame 0x00CC is not sended to the board B, because on that side i received always 0x0000[/quote]
&lt;p&gt;Do you receive 0x0000 in Board B when BoardA sends 0X00CC? or you receive nothing on BoardB?&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;When you send 0X00CC from BoardA and receive 0x0000 on BoardB, then it looks like the SPI pins configuration issue and&amp;nbsp;&lt;strong&gt;NOT&lt;/strong&gt; an issue with priorities.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;When you send 0x00CC from BoardA and receive nothing on BoardB (you should confirm with pins connected to logic analyzer that BoardA actually sends this data over SPI lines to BoardB), then we can focus on BoardB only.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and GPIOTE interrupt problem</title><link>https://devzone.nordicsemi.com/thread/444534?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 13:48:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec2bfdb7-759b-4639-8775-7e6d491d74b4</guid><dc:creator>FedericoDeSario</dc:creator><description>&lt;p&gt;An important thing that I forgot is that i started from&amp;nbsp;ble_app_uart example, and i added the SPI module (following&amp;nbsp;the SPI example) and the interrupt irq_pin_handler.&lt;/p&gt;
[quote userid="6207" url="~/f/nordic-q-a/103442/ble-and-gpiote-interrupt-problem/444455"]I assume that the STOP command from dongle to Board A when through.[/quote]
&lt;p&gt;&lt;br /&gt;The code&amp;nbsp; snippet processing the STOP command is the same of the STARTcommand. It is done in the nus_data_handler that i posted as last snippet. I will repost it here:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void nus_data_handler(ble_nus_evt_t * p_evt)
{

    if (p_evt-&amp;gt;type == BLE_NUS_EVT_RX_DATA)
    {
        ret_code_t err_code;

        char dongle_command[BLE_NUS_MAX_DATA_LEN];
        memset (dongle_command,0,BLE_NUS_MAX_DATA_LEN);
        memcpy (dongle_command, p_evt-&amp;gt;params.rx_data.p_data, p_evt-&amp;gt;params.rx_data.length);
        
        uint16_t cmd;

        NRF_LOG_DEBUG(&amp;quot;Received data from BLE NUS. Writing data on UART.&amp;quot;);
        NRF_LOG_HEXDUMP_DEBUG(p_evt-&amp;gt;params.rx_data.p_data, p_evt-&amp;gt;params.rx_data.length);

        /*Processing of BLE command*/
        if(strcmp(dongle_command,&amp;quot;START\n&amp;quot;) == 0 )
            {
                cmd = 0x00AA;
                err_code = spiTx_fifo_push(&amp;amp;cmd);
                APP_ERROR_CHECK(err_code);
            }
            else if(strcmp(dongle_command,&amp;quot;STOP\n&amp;quot;) == 0 )
            {
                cmd = 0x00CC;
                err_code = spiTx_fifo_push(&amp;amp;cmd);
                APP_ERROR_CHECK(err_code);
            }
            else
            {
              //niente per ora
            }
    }

    //attivo e disattivo led 2 se attivo le notifiche da pc&amp;quot;
    if (p_evt-&amp;gt;type == BLE_NUS_EVT_COMM_STARTED)
    {
    	nrf_gpio_pin_clear(LED_2);
    }

    if (p_evt-&amp;gt;type == BLE_NUS_EVT_COMM_STOPPED)
    {
    	nrf_gpio_pin_set(LED_2);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Due to the fact that the function is the same for START and STOP command, i can&amp;#39;t realize why the START command works but the STOPcommand not.&lt;br /&gt;&lt;br /&gt;To be precise, if i send firstly the STOP command, it is correctly received by the board A and correctly received by board B.&lt;br /&gt;&lt;br /&gt;The problem is after I send the start command, in the board B fsm goes to 1 and board B start to execute the if part relative to fsm == 1.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Trying a lot, i can see over the log of board A that the STOP command is received by the board A&amp;nbsp; (also when is in the IRQ routine) but it seems that che frame 0x00CC is not sended to the board B, because on that side i received always 0x0000. It seems that the IRQ interrupt (so the gpiote interrupt) &amp;quot;wins&amp;quot; over the SPI communication. And this is really strange becouse as we can see, I don&amp;#39;t&amp;nbsp;send immediatly the frames (and so also the STOP frame) over SPI but i put them in a fifo and when the board ends all the interrupts it sends in order the data over SPI.&lt;br /&gt;&lt;br /&gt;Here the code that manage the SPI sending of data:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void spi_fifo_process()
{
    uint16_t element;
    uint16_t queue_elements;
    ret_code_t err_code;

    /*Gestione del dato ricevuto via BLE e salvato in m_spiTx_fifo*/

    queue_elements = spiTx_fifo_utilization_get();  //vedo quanti elementi sono nel fifo di trasmissione

    for (int i=0; i&amp;lt;queue_elements; i++)  //invio tutti gli elementi nel fifo via SPI all&amp;#39;FPGA
    {
        err_code = spiTx_fifo_pop(&amp;amp;element); //tolgo un dato dal fifo di trasmissione SPI (verso FPGA) e lo salvo in data
        APP_ERROR_CHECK(err_code);
        spi_tx_buf[0] = element &amp;gt;&amp;gt; 8;        //Ogni elemento del fifo e&amp;#39; da 2 byte ma la trasmissione SPI e&amp;#39; a 1 byte quindi devo spezzare l&amp;#39;elemento in due
        spi_tx_buf[1] = (uint8_t)element;

        spi_xfer_done = false;    //indica che parte la trasmissione (torna true quando alla fine della trasmissione SPI parte l&amp;#39;SPI handler)
        err_code = nrf_drv_spi_transfer(&amp;amp;m_spi, spi_tx_buf, spi_tx_buf_lenght, spi_rx_buf, spi_rx_buf_lenght); //trasmissione SPI (nel frattempo ricevo anche un dato in spi_rx_buf)
        APP_ERROR_CHECK(err_code);

        while(!spi_xfer_done) __WFE();
    }

    /*Gestione del dato rivevuto via FPGA da salvare in m_spiRx_fifo e mandare via BLE*/
    
    if (!ble_tx_active)   //se sto gi&amp;#239;&amp;#191;&amp;#189; trasmettendo via BLE salto questo blocco
    {
        queue_elements = spiRx_fifo_utilization_get();
        for (int i=0; i&amp;lt;queue_elements; i++) 
        {
            err_code = spiRx_fifo_pop(&amp;amp;element); //tolgo un dato dal fifo di ricezione SPI (da FPGA) e lo salvo in data
            nusTx[i*2] = element &amp;gt;&amp;gt; 8;
            nusTx[i*2+1] = (uint8_t)element;  //ogni due elementi consecutivi di nusTx sono un elemento di data (ovvero un dato da 2 byte ricevuto via SPI dall&amp;#39;FPGA)
        }

        if (queue_elements &amp;gt; 0)  //se effettivamente sono stati ricevuti elementi dall&amp;#39;FPGA
        {
            NRF_LOG_DEBUG(&amp;quot;Ready to send data over BLE NUS&amp;quot;);

            ble_tx_active = true;        //una volta Ricevuti i dati, setto ble_tx_active su true  che vuol dire che sto mandando dati via BLE (durante la trasmissione BLE ignoro i dati ricevuti dall&amp;#39;FPGA)
            txSize = 2*queue_elements; //la dimensione del buffer che viene inviato via ble (nusTx) e&amp;#39; pari al doppio di quella spiRx (come detto prima)
            txRdPtr = 0;            //Questo dice da dove partire a mandare i dati in ble_data_send (ovviamente parte da zero essendo l&amp;#39;inizio della trasmissione BLE)      
            ble_data_send();    //Si occupa della trasmissione BLE del dato ricevuto via SPI, gestendolo come una notifica che viene mandata via BLE (al controller o dongle) sfruttando il NUS
        }
    }

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then this function is called here:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void idle_state_handle(void)
{   
    spi_fifo_process();
    UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
    nrf_pwr_mgmt_run();

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;(idle_state_handle is the only function in the main loop).&lt;/p&gt;
&lt;p&gt;Sorry for the comments in italian.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="6207" url="~/f/nordic-q-a/103442/ble-and-gpiote-interrupt-problem/444455"] You need to make sure that the SPI interrupt handler in the Board A is higher in priority than the loop that is toggling the pin.[/quote]
&lt;p&gt;&lt;br /&gt;The IRQ prio of the gpiote is set to 7 while the IRQ prio of SPI is set to 5.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and GPIOTE interrupt problem</title><link>https://devzone.nordicsemi.com/thread/444455?ContentTypeID=1</link><pubDate>Tue, 05 Sep 2023 10:12:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15724923-abb0-4ffb-b0ba-665f34d40c22</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user=""]The problem is that when I send the STOP command from dongle to Board A, this seems to be ignored.[/quote]
&lt;p&gt;I assume that the STOP command from dongle to Board A&amp;nbsp;went through. Then it is the matter of finding out if the code in Board A has processed the incoming STOP command. I do not see the code snippet of Board A processing the STOP command. Also I do not see the context in which all these functions are called. You need to make sure that the SPI interrupt handler in the Board A is higher in priority than the loop that is toggling the pin.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>