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

Cannot restart RTC from PPI after STOP, CLEAR tasks

Hi,

I worked on the nrf51 for some years and recently moved over to the nrf52. PPI is a new interface I am exploring. I am having trouble restarting a RTC which was started by the CPU and Stopped by PPI.

If the RTC is started from PPI(say some GPIOTE event assigned to PPI), I have no trouble with the STOP, CLEAR, START task sequence.

If the RTC is first started from the CPU (say in main before the while loop), I use PPI to STOP the RTC, immediately clear the RTC CC0 event, then restart it later with RTC_START using PPI. It does not start, but I do see the counter get cleared. Is there something I am possibly missing?

This is non-soft device by the way. I'm working off the RTC example... although in the future I will introduce the softdevice

Hi,

Instead of using the driver APIs, I tried with just the HAL and still turn up with the same results. I also switched to RTC0 and RTC2... same behavior. Here is the example I am testing

void gpioConfig(void)
{
   
  NRF_GPIOTE->CONFIG[0] = ( (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos) | 
                                       (22 << GPIOTE_CONFIG_PSEL_Pos) | 
                  (GPIOTE_CONFIG_POLARITY_Toggle << GPIOTE_CONFIG_POLARITY_Pos) |                                                      
                       (GPIOTE_CONFIG_OUTINIT_High << GPIOTE_CONFIG_POLARITY_Pos) );
    

  
}

static void clock_config(void)
{

    // Recommended by Nordic before using RTC
    // See nRF52832_Rev_2_Errata_v1.0 | 3.3 [20] RTC: Register values are invalid
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART = 1;
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) {}
    NRF_RTC2->TASKS_STOP = 0;
	
}


static void rtc_config(void)
{

NRF_RTC2->EVTENSET = RTC_EVTENSET_COMPARE0_Enabled <<RTC_EVTENSET_COMPARE0_Pos; 
   
    NRF_RTC2->PRESCALER = 2183;
    NRF_RTC2->CC[0] = 1;

}


static void ppi_config(void)
{
    ret_code_t err_code;
	
    NRF_PPI->CH[0].EEP = (uint32_t) &NRF_RTC2->EVENTS_COMPARE[0];
    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_RTC2->TASKS_STOP;
    NRF_PPI->FORK[0].TEP = (uint32_t)&NRF_RTC2->TASKS_CLEAR;
    NRF_PPI->CHEN |= (PPI_CHEN_CH0_Enabled << PPI_CHEN_CH0_Pos);
    
    NRF_PPI->CH[1].EEP = (uint32_t) &NRF_RTC2->EVENTS_COMPARE[0];
    NRF_PPI->CH[1].TEP = (uint32_t)&NRF_RTC2->TASKS_START;
    NRF_PPI->FORK[1].TEP = (uint32_t)&NRF_GPIOTE->TASKS_OUT[0];  
    NRF_PPI->CHEN |= (PPI_CHEN_CH1_Enabled << PPI_CHEN_CH1_Pos);
    
 
}

int main(void)
{

    NRF_POWER->DCDCEN = 1;                          
    gpioConfig();

    
    rtc_config();
    ppi_config();
   clock_config();
	
   NRF_RTC2->TASKS_START=1;

    while(1)
    {
        __WFE();
    }
}
Parents
  • The way you have it written it forces clear/compare/stop and start to all happen on the same pclk cycle. I'm fairly sure this is not possible. Plus there really is no point in that. Just do the clear and forget stop/start. It is all the same logically in your code.

    Once you start the timer it just keeps running. Then any cc event will just perform a clear and your gpio action, but the timer keeps running and starts over at 0x0.

Reply
  • The way you have it written it forces clear/compare/stop and start to all happen on the same pclk cycle. I'm fairly sure this is not possible. Plus there really is no point in that. Just do the clear and forget stop/start. It is all the same logically in your code.

    Once you start the timer it just keeps running. Then any cc event will just perform a clear and your gpio action, but the timer keeps running and starts over at 0x0.

Children
Related