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

can not put sleep mode in nrf51822

hi

i am using nrf51822 s110 and 7.2.0 SDK. here, i am trying to put cpu in sleep mode, but i can not. i found the issue RTC1 interrupt call every 5ms. i have configured RTC1 as 5ms.

my question is, if it possible system put in off mode without stop RTC1 interrupt.

if can not possible, please tell me another solution.

thanks, here i have include my code

int main(void)
{
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);// stop RTC1,set Timer buffer size, tick number
    setup_RTC1_100ms_timer();
  
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);// set memory buffer
  	ble_stack_init_total();

    uart_init();// set UART Tx and Rx pins, set the priority of UART, and enable interrupt of UART
    gap_params_init();// set minimum interval, maximum interval, slave latency, supervision timeout, GAP security, Name, encoding and sending
    services_init();// send the data from BLE to UART, set 16-bit UUID to 128-bit UUID, set RX characteristics(0x0003), set Tx characteristics(0x0002)
    advertising_init();//builds a structure to be passed to the stack when starting advertising, Encodes the required advertising data and passes it to the stack.
    conn_params_init();//Set the connection params in stack and fetch connection params from stack.
    sec_params_init();// initializing security parameters.
    sd_ble_gap_adv_stop();
//    advertising_start();
	(void)pstorage_init();
	
	param.block_size = 16;
	param.block_count = 5056;
	param.cb = example_cb_handler; 
	
	(void)pstorage_register(&param,&block_id); 
     while(block_id.block_id!=0x00027000);		 
	

   for(;;) // mainloop
   	{			
			
    	if(tUserKey.tUserTsk.Top_tsk == Top_Buttontsk)
			{
				button_tsk(&tUserKey,&tKeyBoard);
			}
			if(tUserKey.tUserTsk.Top_tsk == Top_Ledtsk)
			{
				Ledtsk(&tUserKey);
			}
			if(tUserKey.tUserTsk.Top_tsk == Top_UItsk)
			{
				UiTsk(&tUserKey,&tKeyBoard,&tLock);
			}			
			if(tUserKey.tUserTsk.Top_tsk == Top_LockTsk)
			{
				Lock_Tsk(&tUserKey,&tLock);				
			}

			EnterSleep(&tUserKey,&tKeyBoard);				
		}
}

void EnterSleep(USERKEY *tUserKey,KEYBOARD * tKeyBoard)  // handle system task and goes sleep
{
	
		if((tUserKey->tUserTsk.Top_tsk==0x00)&& (IsTimerUsed()==false))
    { 				
				Ext_interrupt_enable(CLOSE);
				hw_UartEnableTx(CLOSE);
				hw_UartEnableRxNOINT(CLOSE);
				Btn_interrupt_enable(OPEN); 
				Ext_interrupt_enable(OPEN);              //FOR INT FROM LOCK & ENCODER			
//				if(tUserKey->tUserTsk.Top_tsk==0x00)
//				{
				sleep();
//				}			
        Ext_interrupt_enable(CLOSE);			
				tUserKey->HeaderChangeFlg = 0;
        //tUserKey->cLockWrongTimes = 0;
        tUserKey->unblockedInProgress = 0;
        tUserKey->tMenu.newMenuIndex = tUserKey->tMenu.MenuIndex = BlankMenu;
        tKeyBoard->currPWCursor = 0;
        tKeyBoard->DoubleClickFlg = 0;
        tKeyBoard->key_old = KeyVoid;
        tUserKey->lck_chagre_flg = 0;
				
    }
		
}

void setup_RTC1_100ms_timer(void)
{
//
//  Set up clock source for RTC (both RTC0 and RTC1
//

    NRF_RTC1->TASKS_STOP = 1;                                                   //  Must be stopped to be able to write PRESCALER
    NRF_RTC1->PRESCALER = 164;                                  //   5 ms changed by satheesh from 100 ms 
	//  
    // Enable TICK event and TICK interrupt:
    //
    NRF_RTC1->EVTENSET = (RTC_EVTENSET_TICK_Enabled << RTC_EVTENSET_TICK_Pos);
    NRF_RTC1->INTENSET = (RTC_INTENSET_TICK_Enabled << RTC_INTENSET_TICK_Pos);

	// set up compare register to 0
	NRF_RTC1->INTENSET = (RTC_INTENSET_COMPARE0_Enabled << RTC_INTENSET_COMPARE0_Pos);
	NRF_RTC1->EVTENSET = (RTC_EVTENSET_COMPARE0_Enabled << RTC_EVTENSET_COMPARE0_Pos);
    NRF_RTC1->CC[0] = 2; // original 60

//NRF_RTC1->INTENSET = (RTC_INTENSET_COMPARE1_Enabled << RTC_INTENSET_COMPARE1_Pos);
//	NRF_RTC1->EVTENSET = (RTC_EVTENSET_COMPARE1_Enabled << RTC_EVTENSET_COMPARE1_Pos);
//    NRF_RTC1->CC[1] = 2; 
	
//	NRF_RTC1->INTENSET = (RTC_INTENSET_COMPARE2_Enabled << RTC_INTENSET_COMPARE2_Pos);
//	NRF_RTC1->EVTENSET = (RTC_EVTENSET_COMPARE2_Enabled << RTC_EVTENSET_COMPARE2_Pos);
//    NRF_RTC1->CC[2] = 200; 
		
    NVIC_ClearPendingIRQ(RTC1_IRQn);
    NVIC_EnableIRQ(RTC1_IRQn);                                                  // Enable Interrupt for RTC1 in the core

    NRF_RTC1->TASKS_START = 1;
}



void RTC1_IRQHandler(void)
{
   uint8_t cTempdata,i;
   static uint32_t output = 0;
    if(NRF_RTC1->EVENTS_TICK != 0)
	{               
       NRF_RTC1->EVENTS_TICK = 0;                   //  clear the event
       realTimeTick++;
       cTempdata = realTimeTick/0xc8;// changed as by satheesh 0x64 from 0x0a
       realTimeTick = realTimeTick%0xc8;// changed as by satheesh 0x64 from 0x0a
	   tUserKey.tRealTime.second += cTempdata;
	   nDelayDiscount = 0x06;
	   (void)CheckRealTime(&tUserKey);
	}
    
	if ((NRF_RTC1->EVENTS_COMPARE[0] != 0) && ((NRF_RTC1->INTENSET & RTC_INTENSET_COMPARE0_Msk) != 0))
    {
			
	   NRF_RTC1->EVENTS_COMPARE[0] = 0;  //  clear the event 
	   NRF_RTC1->TASKS_CLEAR = 1;
	   NRF_RTC1->CC[0]=2;
    }
	
	
if ((NRF_RTC1->EVENTS_COMPARE[1] != 0) && ((NRF_RTC1->INTENSET & RTC_INTENSET_COMPARE1_Msk) != 0))
{
		
	if(Timer[ButtonTimer].TimerInUse > 0)
        {		 				
            Timer[ButtonTimer].TimeOut -= 10;
						if(Timer[ButtonTimer].TimeOut <= 0)
            {
								tUserKey.tUserTsk.Top_tsk=Top_Buttontsk;
                tUserKey.tUserTsk.Buttontsk=bt_timeout;
            }    
        }
        if(Timer[LedTimer].TimerInUse > 0)
        {
					 Timer[LedTimer].TimeOut -= 10;
            if(Timer[LedTimer].TimeOut <= 0)
            {						
							tUserKey.tUserTsk.Top_tsk=Top_Ledtsk;
               tUserKey.tUserTsk.LedTsk=Led_TimeOut; 
            }    
        }
			 if(Timer[UiTimer].TimerInUse > 0)
        {
            Timer[UiTimer].TimeOut -= 10;
            if(Timer[UiTimer].TimeOut <= 0)
            {
								tUserKey.tUserTsk.Top_tsk=Top_UItsk;
               tUserKey.tUserTsk.UItsk=Ui_TimeOut;
            }    
        }
        if(Timer[LockTimer].TimerInUse > 0)
        {
            Timer[LockTimer].TimeOut -= 10;
            if(Timer[LockTimer].TimeOut <= 0)
            {
							tUserKey.tUserTsk.Top_tsk =Top_LockTsk;
							tUserKey.tUserTsk.LockTsk = Lock_TimeOut;         
            }    
        }
        if(Timer[SysTimer].TimerInUse > 0)
        {
            Timer[SysTimer].TimeOut -= 10;
            if(Timer[SysTimer].TimeOut <= 0)
            {
							tUserKey.tUserTsk.Top_tsk=Top_Systsk;
              tUserKey.tUserTsk.Systsk=Sys_TimeOut; 
            }    
        } 
        if(Timer[EncoderTimer].TimerInUse > 0)
        {
            Timer[EncoderTimer].TimeOut -= 10;
            if(Timer[EncoderTimer].TimeOut <= 0)
            {          
							tUserKey.tUserTsk.Top_tsk = Top_LockTsk; 
							tUserKey.tUserTsk.EncoderTsk = En_TimeOut;
            }    
        }
				if(Timer[BluetoothTimer].TimerInUse > 0)
        {
            Timer[BluetoothTimer].TimeOut -= 10;
            if(Timer[BluetoothTimer].TimeOut <= 0)
            {
               
            }    
        }	
				if(Timer[Ble_sw_Timer].TimerInUse > 0)
        {
            Timer[Ble_sw_Timer].TimeOut -= 10;
            if(Timer[Ble_sw_Timer].TimeOut <= 0)
            {
							tUserKey.Ble_enable_flg=2;
            }    
        }
				if(Timer[ExInt_Timer].TimerInUse > 0)
        {
            Timer[ExInt_Timer].TimeOut -= 10;
            if(Timer[ExInt_Timer].TimeOut <= 0)
            {
							TimerKill(ExInt_Timer);
						tUserKey.reset_flg=1;
						//tUserKey.tUserTsk.Top_tsk=Top_Resettsk;
            }    
        }
			NRF_RTC1->EVENTS_COMPARE[1] = 0;  //  clear the event 
			NRF_RTC1->TASKS_CLEAR = 1;
			NRF_RTC1->CC[1]=2;
	}

	}
Related