Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Is there a provision in the SDK to handle the event NRF_SPIM_EVENT_STARTED?

Because if there is, I'm not seeing it. It seems to me that the SDKv14 has asks you where you want your event handler function like this:

APP_ERROR_CHECK(nrf_drv_spi_init(&spi_0, &spi_config_0, spi_0_event_handler, NULL));

Where spi_0_event_handler() is going to be used.

And later I have something like this:

void spi_0_event_handler(nrf_drv_spi_evt_t const * p_event, void *p_context)
{
   spi_xfer_done = true;
   NRF_LOG_INFO("Transfer completed.");

}

This works for ENDTX event. But I never said I was interested in ENDTX. What if I wanted NRF_SPIM_EVENT_STARTED ?  Is there a way to "register" which events I want to call the event_handler with the SPIM peripheral/driver/api/hal? Or would I have to use PPI to set a SWI?

  • Hello,

    In the SPI example which you refer to in the SDK, the event handler takes in an event which only has one event, ENDTX. spi_event_handler() has only two inputs, one for the data, and one for the event: nrf_drv_spi_evt_t, which holds the variable nrf_drv_spi_evt_type_t, which again only has one event type, NRF_DRV_SPI_EVENT_DONE.

    I think the easiest way to hook up the NRF_SPIM_EVENT_STARTED would be to use the PPI. Note that NRF_SPIM_EVENT_STARTED = NRF_SPIM0->EVENTS_STARTED (for SPIM0).

    It would look something like this:

    void EGU_setup(void)
    {
        #define CHANNEL_0 0
        NRF_PPI->CH[CHANNEL_0].EEP = NRF_SPIM0->EVENTS_STARTED;
        NRF_PPI->CH[CHANNEL_0].TEP = NRF_EGU0->TASKS_TRIGGER[0];
        
        NRF_EGU0->INTENSET = EGU_INTENSET_TRIGGERED0_Msk;
        NVIC_EnableIRQ(SWI0_EGU0_IRQn);
        
        NRF_PPI->CHENSET = (1 << CHANNEL_0);
    }
    
    void SWI0_EGU0_IRWHandler(void)
    {
        if (NRF_EGU->EVENTS_TRIGGERED[0])
        {
            //This is the timeout handler that triggers after NRF_SPIM0->EVENTS_STARTED
            NRF_EGU0->EVENTS_TRIGGERED[0] = 0;
        }
    }

    Best regards,

    Edvin

  • Edvin,

    This makes sense to me. The Event Generator Unit has an array of events, you register each one to an array location, and they use PPI to tie into SoftWare Interrupt 0 (because only 6 channels and some are for the radio).

    In this case, the is the EGU hardware peripheral? Or is the EGU some nordic software to easily work with the existing events, PPI, and SWI components that are in the hardware?

  • Hello,

    The EGU is a peripheral, as you can see here.

    A list of the tasks and events for the EGU is found here.

    So the EGU is a physical peripheral, but you can use it for interrupt calls on the CPU, instead of only triggering another peripheral.

    BR,

    Edvin

  • Edvin, I closed the ticket because your answer was great. But can you please explain the difference in the SWI and EGU peripherals? I'm having trouble understanding why they share resources, and that EGU seems to be able to do what SWI does and perhaps more? Is it that SWI is really just a support component for EGU?

Related