Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Timeslot question

Dear Nordic Engineers

I would like to sample the ADC between advertisements or connections, that is when the RF is sleeping, so I want to use Timeslot, I see there is a tutorial:devzone.nordicsemi.com/.../setting-up-the-timeslot-api

I refer to this example and make changes in the ble_app_template routine. I am using the 17.0.2 version of the SDK, so I have made a little modification. The modifications are as follows:
1.In "timeslot.c",replaced the header file "softdevice_handler.h" with "nrf_sdh.h".

2.As sys_evt_dispatch is not there in main.c,so I added the following line to main.c

3.I call NRF_SDH_SOC_OBSERVER(m_time_slot_soc_observer,0,time_slot_soc_evt_handler,NULL); in  ble_stack_init(void)

I download the program into the NRF52832 DK and opened LOG.I found that the timeslot is only executed one times. ,LED4 not blinking it stays on

This is my timeslot event handler function

I don't know why this happens,I would like Timeslot to turn on  every time the RF  sleeps.

Please give me some advices.

Best regards.

  • Hi,

    Could you try to request a new timeslot after it ends, similar to the following:

    static bool keep_running = true;
    void timeslot_on_sys_evt(uint32_t sys_evt, void * p_context)
    {
        uint32_t err_code;
        switch (sys_evt)
        {
            case NRF_EVT_RADIO_SESSION_IDLE:
                   // NRF_LOG_INFO("NRF_EVT_RADIO_SESSION_IDLE");
                    if (keep_running)
                    {
                        err_code = m_request_earliest(NRF_RADIO_PRIORITY_NORMAL);
                        APP_ERROR_CHECK(err_code);
                    }
                    break;
            case NRF_EVT_RADIO_SESSION_CLOSED:
                NRF_LOG_INFO("NRF_EVT_RADIO_SESSION_CLOSED");
                break;
            case NRF_EVT_RADIO_BLOCKED:
            case NRF_EVT_RADIO_CANCELED: // Fall through.
                if (keep_running)
                {
                    err_code = m_request_earliest(NRF_RADIO_PRIORITY_NORMAL);
                    APP_ERROR_CHECK(err_code);
                }
                break;
            default:
                NRF_LOG_INFO("timeslot_on_sys_evt: %d\r\n", sys_evt);
                break;
        }
    }
    void timeslot_on_sys_evt(uint32_t, void *);
    /* Define a nrf_sdh_soc event observer to receive SoftDevice system events. */
    NRF_SDH_SOC_OBSERVER(m_sys_obs, 0, timeslot_on_sys_evt, NULL);

    uint32_t m_request_earliest(enum NRF_RADIO_PRIORITY priority)
    {
        timeslot_request.request_type                = NRF_RADIO_REQ_TYPE_EARLIEST;
        timeslot_request.params.earliest.hfclk       = NRF_RADIO_HFCLK_CFG_XTAL_GUARANTEED;
        timeslot_request.params.earliest.priority    = priority;
        timeslot_request.params.earliest.length_us   = TS_LEN_US;
        timeslot_request.params.earliest.timeout_us  = NRF_RADIO_EARLIEST_TIMEOUT_MAX_US;
        return sd_radio_request(&timeslot_request);
    }

    Regards,

    Priyanka

  • Dear Priyanka

    Thank your for your good advices.I try to add earliest request into NRF_EVT_RADIO_SESSION_IDLE,it's working.However I turn off the keep_running judgment,because it will cause an error.

    Thank you for you support.

    Best regards.

Related