Enable SPI interrupt into GPIOTE handler

Dear Sirs,

In an application, an external GPIO Interrupt triggers the control of an SPI device. This means that the application would be running into the GPIO service routine and, at the same time, enabling the management of the SPI interrupts.

I’m working on nRF5_SDK_17.1.0 and using the SES IDE environment for a nRF52-DK HW.

I have been checking the signals using this nRF52-DK. I have verified that changing manually the interrupt pin, the device enters into the GPIO handler routine. Into this routine I manage the SPI device control. I see that the SPI generates the right clock and data signals in the execution of a nrf_drv_spi_transfer() function. After this, the program waits by calling the function wait_end_xfer_accel(), which tests for the flag that will be modified by the SPI interrupt. However, the SPI interrupt is not serviced and the flag is not modified. So, it looks like the SPI interrupts are not enabled while the GPIO irq is being serviced.

I have the GPIOTE interrupt level set to 3 in the sdk_config.h file (GPIOTE_CONFIG_IRQ_PRIORITY) and the SPI_IRQ_PRIORITY to value 2. I understand that the driver funtions in the nRF-SDK should manage this automatically, but it doesn’t work,

What could I be missing?

Thank you very much in advance.

Regards,

Joel

Parents
  • Hello,

    Assuming this work when calling nrf_drv_spi_transfer() and wait_end_xfer_accel() from main. Then the most likely issue is that the interrupt priorities for SPI and GPIOTE is not setup correctly, maybe double check the spi_config.irq_priority passed to nrf_drv_spi_init() is indeed 2, do the same with nrf_drv_gpiote_init() to check it's indeed 3.

    Kenneth

Reply
  • Hello,

    Assuming this work when calling nrf_drv_spi_transfer() and wait_end_xfer_accel() from main. Then the most likely issue is that the interrupt priorities for SPI and GPIOTE is not setup correctly, maybe double check the spi_config.irq_priority passed to nrf_drv_spi_init() is indeed 2, do the same with nrf_drv_gpiote_init() to check it's indeed 3.

    Kenneth

Children
  • Hello Keneth,

    Thank you for your message.

    Related to the nrf_drv_gpiote_init() function, there is a call to it like this:

        if (!nrf_drv_gpiote_is_init())
        {
            err_code = nrf_drv_gpiote_init();
            APP_ERROR_CHECK(err_code);
        }
    

    I see that the nrf_drv_gpiote_init() functions is defined in nrf_drv_gpiote.h file like this:

    #define nrf_drv_gpiote_init               nrfx_gpiote_init

    And inside the nrfx_gpiote_init) function is used the definition NRFX_GPIOTE_CONFIG_IRQ_PRIORITY, which I confirm that has the value 3 in the sdk_config.h.

    Related to the nrf_drv_spi_init() function, I follow an example that uses the next code:

    APP_ERROR_CHECK(nrf_drv_spi_init(&spi_sst, &spi_config, spi_sst_event_handler, NULL));

    Where the spi_config structure is created and defined like this:

    nrf_drv_spi_config_t spi_config[2] = {NRF_DRV_SPI_DEFAULT_CONFIG, NRF_DRV_SPI_DEFAULT_CONFIG};

    and then I modify specific variables of the structure for defining the pins:

        spi_config.ss_pin   = SST_SPI_1_SS_PIN;
        spi_config.miso_pin = SST_SPI_1_MISO_PIN;
        spi_config.mosi_pin = SST_SPI_1_MOSI_PIN;
        spi_config.sck_pin  = SST_SPI_1_SCK_PIN;
    

    but I don’t change the value of spi_config.irq_priority.

    The NRF_DRV_SPI_DEFAULT_CONFIG structure is defined in the nrf_drv_spi.h file with the value:

    .irq_priority = SPI_DEFAULT_CONFIG_IRQ_PRIORITY,

    Which has a default value of 6 in the sdk_config.h. I have not changed this because I misunderstood that the definition to be changed was SPI_IRQ_PRIORITY to value 2. So, I understand that I should also change SPI_DEFAULT_CONFIG_IRQ_PRIORITY to 2.  I Will check it.

    By the way, what is the utility of the SPI_IRQ_PRIORITY definition?

    Regards,

    Joel

  • Hello Keneth,

    I have checked the change in using SPI_DEFAULT_CONFIG_IRQ_PRIORITY to 2, and it looks it works.

    By the way, what is the utility of the SPI_IRQ_PRIORITY definition?

    Regards,

    Joel

  • Hello Joel,

    SPI_IRQ_PRIORITY will override the SPI_DEFAULT_CONFIG_IRQ_PRIORITY if both are defined in your sdk_config.h file because the legacy symbol will take precedence. For more on this, please see nrfx migration guide here https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/nrfx_migration_user_guide.html?cp=8_1_2_7_0#getting_started_replace_nrf_drv_options_keep 

    Best regards,

    Vidar 

  • Hello Vidar,

    Thank you for your message.

    What I had in the code was the next:

    #ifndef SPI_IRQ_PRIORITY
    #define SPI_IRQ_PRIORITY 2  
    #endif
    
    #ifndef SPI_DEFAULT_CONFIG_IRQ_PRIORITY
    #define SPI_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #endif

    Considering this, I thought that the SPI_IRQ would have a greater priority that the GPIOTE (2 over 3 respectively). However, this didn't work until I did the  next:

    #ifndef SPI_IRQ_PRIORITY
    #define SPI_IRQ_PRIORITY 6
    //#define SPI_IRQ_PRIORITY 2
    #endif
    
    #ifndef SPI_DEFAULT_CONFIG_IRQ_PRIORITY
    //#define SPI_DEFAULT_CONFIG_IRQ_PRIORITY 6
    #define SPI_DEFAULT_CONFIG_IRQ_PRIORITY 2
    #endif

    What I have seen searching into the code of the nrf SPI driver is that the SPI_IRQ_PRIORITY value is not used in any part of the project. It uses the SPI_DEFAULT_CONFIG_IRQ_PRIORITY value. Modifying this last value, then it works.

    Regards,

    Joel

  • Hello Joel,

    Sorry, I mistook SPI_DEFAULT_CONFIG_IRQ_PRIORITY for NRFX_SPI_DEFAULT_CONFIG_IRQ_PRIORITY. The former is the old configuration symbol which will take precedence. 

    As you already pointed out, the SPI_IRQ_PRIORITY symbol is not being applied anywhere. We should have removed it from the sdk_config.h to avoid confusions like these. 

    Regards,

    Vidar

Related