This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPIS not working with nrf_pwr_mgmt_run

Hey all

In my current project I could set up an SPI communication, where the SPI-slave is on the nordic side. This works fine when I have __WFE() in my main loop, however when I replace __WFE() by nrf_pwr_mgmt_run() no SPI data is received anymore.

    while (true) // endless main loop
    {
        if(NRF_LOG_PROCESS() == false)
        {
//            __WFE();
            nrf_pwr_mgmt_run();
        }
    }

Can anyone give me a hint, why this does not work? And whats the

  • As you can see in most our example projects, nrf_pwr_mgmt_run() is called as part of idle_state_handle() in order to make sure there are no pending log operations, before it goes to sleep until the next event occurs. Please try that on your end as well. If not, please try debugging and go step by step when you go to sleep to see what happens, are you sure you trig a new event to wake the device up?

    /**@brief Function for handling the idle state (main loop).
     *
     * @details If there is no pending log operation, then sleep until next the next event occurs.
     */
    static void idle_state_handle(void)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }

    Best regards,

    Simon

  • Hello Simon
    Thanks for your response. I got it to work, so that the event-hander of the SPI gets called, with the event NRFX_SPIS_XFER_DONE, however the received data len is allways 0, unless I run the code in debug mode, even  without breakpoints I get the expected data size. Do you have any hints how to resolve this?

  • Hi

    I discussed this with a colleague, and this sems to be due to the SPIS having a longer wake-up time when waking up from sleep than most other peripherals. This is only documented in the nRF52832 PS, but is valid for the nRF52840 as well (we're working on getting it in a future revision).

    Please take this into consideration when waking the device up so that the SPIS peripheral is able to get started properly before starting operations.

    Best regards,

    Simon

  • Hello Simon
    Thanks for your efforts. This makes sense to me, regarding the behavior I've observed. What is not clear to me, where can I do that:

    take this into consideration when waking the device up so that the SPIS peripheral is able to get started properly before starting operations.

    Is this something in can configure somewhere? Or is this something the peer-device has to follow, so it has some delay after enabling the CS?

  • Hi

    In our SPIS example project, we enable constant latency mode on startup in order to mitigate this (see snippet below). It should also be okay to add a delay of ~10us between CS low and the first clock cycle for instance.

        // Enable the constant latency sub power mode to minimize the time it takes
        // for the SPIS peripheral to become active after the CSN line is asserted
        // (when the CPU is in sleep mode).
        NRF_POWER->TASKS_CONSTLAT = 1;

    Best regards,

    Simon

Related