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

How can i get the state of radio?

Hi, I am using nrf51822 with s110 softdevice version 8.0.

Is there any way i can know the state of my radio at some point in the code execution? In short I want to access NRF_RADIO->STATE register using softdevice. Are there any softdevice calls for this??

Regards.

Parents
  • Hi,

    While it should be possible to read the info out of the register, I think it is a better idea to set up the programmable peripheral interface(PPI) to listen to the radio events and then do something based on that.

    As an example the following code toggles pin 24 on the event NRF_RADIO->EVENTS_READY

    void blinkyradio_ppi_init(void)
    {
        uint32_t err_code = NRF_SUCCESS;
        
        if(!nrf_drv_gpiote_is_init())
        {
            err_code = nrf_drv_gpiote_init();
            APP_ERROR_CHECK(err_code);
        }
        
        NRF_GPIO->DIRSET = 0xFFFF0000UL;
        NRF_GPIO->OUTSET = 0xFFFF0000UL;
        NRF_GPIO->OUTCLR = 0xFFFF0000UL;
        
        //Configure GPIO on pin 24
        NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos)
                                |((24) << GPIOTE_CONFIG_PSEL_Pos)
                                | (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos);
        
        
        NRF_PPI->CH[12].EEP = (uint32_t)(&NRF_RADIO->EVENTS_READY);
        NRF_PPI->CH[12].TEP = (uint32_t)(&NRF_GPIOTE->TASKS_OUT[0]);    //Toggle pin 24
        
        NRF_PPI->CHENSET |= (1 << 12);
    }
    

    Does this answer your question?

    Best regards,

    Øyvind

Reply
  • Hi,

    While it should be possible to read the info out of the register, I think it is a better idea to set up the programmable peripheral interface(PPI) to listen to the radio events and then do something based on that.

    As an example the following code toggles pin 24 on the event NRF_RADIO->EVENTS_READY

    void blinkyradio_ppi_init(void)
    {
        uint32_t err_code = NRF_SUCCESS;
        
        if(!nrf_drv_gpiote_is_init())
        {
            err_code = nrf_drv_gpiote_init();
            APP_ERROR_CHECK(err_code);
        }
        
        NRF_GPIO->DIRSET = 0xFFFF0000UL;
        NRF_GPIO->OUTSET = 0xFFFF0000UL;
        NRF_GPIO->OUTCLR = 0xFFFF0000UL;
        
        //Configure GPIO on pin 24
        NRF_GPIOTE->CONFIG[0] = (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos)
                                |((24) << GPIOTE_CONFIG_PSEL_Pos)
                                | (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos);
        
        
        NRF_PPI->CH[12].EEP = (uint32_t)(&NRF_RADIO->EVENTS_READY);
        NRF_PPI->CH[12].TEP = (uint32_t)(&NRF_GPIOTE->TASKS_OUT[0]);    //Toggle pin 24
        
        NRF_PPI->CHENSET |= (1 << 12);
    }
    

    Does this answer your question?

    Best regards,

    Øyvind

Children
Related