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

TIMER2 issue with soft device

i could not run timer2 with soft device,. if i start initiaize TIMER2 the bluetooth advertise has disabled. i need this timer to timeout my flow function. i think softdevice has stopped my function. my execution timeslot is high compare. can u please help any one

this is my code:

void TimerInit(void)
{
	
	NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
  NRF_CLOCK->TASKS_HFCLKSTART	 = 1;
	while (NRF_CLOCK->EVENTS_HFCLKSTARTED != 0)
    {
        // Do nothing.
    }
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
	
	NRF_TIMER2->TASKS_STOP = 1;   // Stop timer
  NRF_TIMER2->MODE = TIMER_MODE_MODE_Timer;  // taken from Nordic dev zone
  NRF_TIMER2->BITMODE = (TIMER_BITMODE_BITMODE_16Bit << TIMER_BITMODE_BITMODE_Pos);
  NRF_TIMER2->PRESCALER = 4;   // SysClk/2^PRESCALER) =  16,000,000/16 = 1us resolution
  NRF_TIMER2->TASKS_CLEAR = 1; // Clear timer
  NRF_TIMER2->CC[0] = 10000; // Cannot exceed 16bits
  NRF_TIMER2->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;  // taken from Nordic dev zone
 // err_code = sd_nvic_SetPriority(TIMER2_IRQn, APP_IRQ_PRIORITY_LOW);
//APP_ERROR_CHECK(err_code);

//err_code = sd_nvic_EnableIRQ(TIMER2_IRQn);
//APP_ERROR_CHECK(err_code);
	NVIC_SetPriority(TIMER2_IRQn,NRF_APP_PRIORITY_LOW);
  NVIC_EnableIRQ(TIMER2_IRQn); 
	
}


void TIMER2_IRQHandler(void)
{
	unsigned char c;
    if (NRF_TIMER2->EVENTS_COMPARE[0]!=0) {

        // clear compare register event
        NRF_TIMER2->EVENTS_COMPARE[0] = 0;
				//NRF_TIMER2->CC[2] = 3125;
        // increment count
       if(Timer[ButtonTimer].TimerInUse > 0)
        {
            Timer[ButtonTimer].TimeOut -= 10;
						if(Timer[ButtonTimer].TimeOut <= 0)
            {
                event.ButtonTsk |= Button_TimeOut;
                event.TopTsk |= Top_ButtonTsk;
            }    
        }
        if(Timer[LedTimer].TimerInUse > 0)
        {
            Timer[LedTimer].TimeOut -= 10;
            if(Timer[LedTimer].TimeOut <= 0)
            {
                event.LedTsk |= Led_TimeOut;
                event.TopTsk |= Top_LedTsk;
            }    
        }
        if(Timer[UiTimer].TimerInUse > 0)
        {
            Timer[UiTimer].TimeOut -= 10;
            if(Timer[UiTimer].TimeOut <= 0)
            {
                event.UiTsk |= Ui_TimeOut;
                event.TopTsk |= Top_UiTsk;
            }    
        }
        if(Timer[LockTimer].TimerInUse > 0)
        {
            Timer[LockTimer].TimeOut -= 10;
            if(Timer[LockTimer].TimeOut <= 0)
            {
                event.LockTsk |= Lock_TimeOut;
                event.TopTsk |= Top_LockTsk;
            }    
        }
        if(Timer[SysTimer].TimerInUse > 0)
        {
            Timer[SysTimer].TimeOut -= 10;
            if(Timer[SysTimer].TimeOut <= 0)
            {
                event.SysTsk |= Sys_TimeOut;
                event.TopTsk |= Top_SysTsk;
            }    
        } 
        if(Timer[EncoderTimer].TimerInUse > 0)
        {
            Timer[EncoderTimer].TimeOut -= 10;
            if(Timer[EncoderTimer].TimeOut <= 0)
            {
                event.EncoderTsk |= En_TimeOut;
                event.TopTsk |= Top_EncoderTsk;
            }    
        }
				if(Timer[BluetoothTimer].TimerInUse > 0)
        {
            Timer[BluetoothTimer].TimeOut -= 10;
            if(Timer[BluetoothTimer].TimeOut <= 0)
            {
                event.BleTsk |= Ble_TimeOut;
                event.TopTsk |= Top_BleTsk;
            }    
        }
				
				   
	
				if(Timer[Ble_sw_Timer].TimerInUse > 0)
        {
            Timer[Ble_sw_Timer].TimeOut -= 10;
            if(Timer[Ble_sw_Timer].TimeOut <= 0)
            {
//                event.BleTsk |= Ble_TimeOut;
//                event.TopTsk |= Top_BleTsk;
            }    
        }
    }

}
  • Hello Satheesh

    In your code you write to the peripheral registers to start the HF clock, however the application will only have restricted access to these registers when the softdevice is running, see SoC resource requirements of the Softdevice documentation. To control the clock you should use the Softdevice API, found here.

    If the Softdevice has been enabled before you start the timer it will start the HFCLK, so it should not be necessary for you to do it manually.

    Best regards

    Jørn Frøysa

Related