Example for nRF5340 DPPI for use with SPIM and GPIO?

I have a SPI peripheral that will set an interrupt when data is ready (every 50ms). Right now I'm using software to read the data but i was hoping to use DPPI to save on power. I want the DPPI to make the SPI read out the data on every interrupt and only wake up the CPU once I've run out of RAM(with 256KiB buffer, it should take approx 3 minutes).  I've gone through multiple posts about DPPI here. Came up with the following code but it doesn't work.

        uint8_t ppiChannel{};

        nrfx_gpiote_init(1);

        nrfx_gpiote_in_config_t in_config{ NRF_GPIOTE_POLARITY_HITOLO, NRF_GPIO_PIN_NOPULL, false, false, false };

        const auto p1_13 = NRF_GPIO_PIN_MAP(1, 13);
        nrfx_gpiote_in_prealloc_init(p1_13, &in_config, ppiChannel, nullptr);

        nrfx_dppi_channel_alloc(&ppiChannel);

        nrf_gpiote_publish_set(NRF_GPIOTE1_NS, NRF_GPIOTE_EVENT_IN_0, ppiChannel);
        nrf_spim_subscribe_set(NRF_SPIM2, NRF_SPIM_TASK_START, ppiChannel);
        nrfx_dppi_channel_enable(ppiChannel);


I could not find any examples in either ncs or zephyr. Is there some code that i can refer to?
Parents
  • Hi 

    The system you describe should work fine, but I can spot at least one bug in your code. 

    The third parameter in the nrfx_gpiote_in_prealloc_init(..) function should not be the DPPI channel, but the GPIOTE channel. 

    You should have a separate uint8_t variable to store this, and allocate it using the nrfx_gpiote_channel_alloc(uint8_t * p_channel) function, before you call the nrfx_gpiote_in_prealloc_init(..) function. 

    The NRF_GPIOTE_EVENT_IN_0 parameter in the call to nrf_gpiote_publish_set(..) will also need to correspond to the channel you get assigned in the call to nrfx_gpiote_channel_alloc(..). 

    Best regards
    Torbjørn 

  • I tried making your changes but it still doesn't work. My SPI is initalized with zephyr maybe changes are needed in the init code for DPPI to work. Why are there no examples from Nordic semi? Without sample code, getting peripherals to work (not just DPPI) takes a lot of time and effort. Compare this with ST's WB55 which has 300+ examples covering almost all the peripherals.

  • Hi 

    I agree the number of peripheral examples is a bit lacking, and that there is room for improvement in this regard. 

    In your case you probably want to use the nrfx_spim driver, since the Zephyr driver doesn't support all the Nordic specific functionality (such as triggering SPI transcations via DPPI), and there are some good nrfx examples available here

    I would recommend taking a look at one of the nrfx_spim examples and try to setup the SPI in a similar way. 

    I also made my own example recently to try and trigger SPIM transactions via a timer, but unfortunately the example is using registers only. I will try to update the example to use the nrfx driver today or next week so that you can have a look at that as well. You can find the current version of the example here

    Best regards
    Torbjørn

Reply
  • Hi 

    I agree the number of peripheral examples is a bit lacking, and that there is room for improvement in this regard. 

    In your case you probably want to use the nrfx_spim driver, since the Zephyr driver doesn't support all the Nordic specific functionality (such as triggering SPI transcations via DPPI), and there are some good nrfx examples available here

    I would recommend taking a look at one of the nrfx_spim examples and try to setup the SPI in a similar way. 

    I also made my own example recently to try and trigger SPIM transactions via a timer, but unfortunately the example is using registers only. I will try to update the example to use the nrfx driver today or next week so that you can have a look at that as well. You can find the current version of the example here

    Best regards
    Torbjørn

Children
No Data
Related