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

app_timer hangs after i changed intervals through GPIOTE

HELLO,

Now i meet a troubole about app_timer in SDK15.0 with NRF52810.

I use the example 0f central with uart. wtih softdevide.

I creat a app_timer with 100ms interval. if a acc gives no interrupt about few seconds with GPIOTE, app_timer interval will becomes 5s;

And after next acc interrupt comes in GPIOTE, i will stop the running app_timer and restart it with its interval be set  to 100ms.

But ,my trouble is after i stop and restart 100ms app_timer in GPIOTE IRQ, it cann't work quickly.Maybe it hangs.

With the same programming, if i donn't start the 5s app_timer . i can restart 100ms of it quickly after accc interrupt comes.

List my codes as follows:

#define APP_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. */
#define APP_TIMER_OP_QUEUE_SIZE 2 //2; /**< Size of timer operation queues. */

err_code = app_timer_create(&m_inuse_100ms_timer_id,
APP_TIMER_MODE_REPEATED,
INUSE_100ms_timeout_handler);
APP_ERROR_CHECK(err_code);

						
void active_acc_in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
//	    app_timer_stop(m_inuse_5s_timer_id);
//	    app_timer_stop(m_inuse_100ms_timer_id);	
//            nrf_gpio_pin_toggle(LED_BLUE);
	
	   sd_ble_gap_adv_stop();   //important;	
	    
	
      SLIGHT_MOTION_Enter_IDLE_FLAG =0;
//	    printf("ACC\r\n");
	
//			ACC_INT1_STATE = nrf_gpio_pin_read(ACC_INT_PIN);
//	    printf("ACC_INT1_STATE=%d\r\n\r\n",ACC_INT1_STATE);
	
//	  if(ACC_INT1_STATE ==0)
	    KX022_ReadReg(KX022_INT_REL,&INT_REL);
			
	
	
	
	
//	    printf("ffff\r\n");
       
			if(slight_motion_first_start ==0)
			{
			sd_ble_gap_adv_stop();   //important;	
				
			uint32_t app_t1= app_timer_cnt_get();	
//			printf("app_t1=%d\r\n",app_t1);			
				
			uint8_t app_t =app_timer_stop(m_inuse_100ms_timer_id);
//      printf("app_t=%d\r\n",app_t);				
//				app_timer_stop_all();
			
			uint32_t app_t2= app_timer_cnt_get();	
//			printf("app_t2=%d\r\n",app_t2);
				
				
//			err_code = app_timer_create(&m_inuse_100ms_timer_id,                
//                                  APP_TIMER_MODE_SINGLE_SHOT,
//                                   INUSE_100ms_timeout_handler);           
//      APP_ERROR_CHECK(err_code);		
//			nrf_delay_ms(200);	
			
			SLIGHT_MOTION_FLAG =1;
			SLIGHT_MOTION_TO_STATIC_CAL =0;
				
				//should close it after next acc int ;	
				
		 
			m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x01;   //slight motion;
			m_beacon_info[2] = (m_beacon_info[2]&0x0F)|0x10;   //OPEN  STATUS ;
				
			m_beacon_info[13] =0x01;   //soft version;
			m_beacon_info[14] =0;       //reserved;
				
//			advertising_init();
//			sd_ble_gap_tx_power_set((BLE_TX_POWER&0x0F)-6);  //At this place;after ...init();
//			advertising_start();

//      active_pin_set_to_input();	
//			Init_KX022_100ms_ATH_Max_Setting();	
//			
	  KX022_WriteReg(KX022_CNTL1, 0x02);
		KX022_WriteReg(KX022_CNTL3, 0x04);  //0x04>12.5Hz;  0x05>25Hz;  0x0B>6.25Hz;
		KX022_WriteReg(KX022_INC2, 0x3F);
		KX022_WriteReg(KX022_WUFC, 0x01);   //motion detection timer;
		KX022_WriteReg(KX022_ATH, 0xFF);
		KX022_WriteReg(KX022_INC1, 0x00);   //0x30>s active high; 0x20>active low
		KX022_WriteReg(KX022_INC4, 0x02);
		KX022_WriteReg(KX022_ODCNTL, 0x00);  //
		KX022_WriteReg(KX022_LP_CNTL, 0x4B);
		KX022_WriteReg(KX022_BUF_CNTL1, 0x25);
		KX022_WriteReg(KX022_BUF_CNTL2, 0xE0);
    KX022_WriteReg(KX022_CNTL1, 0x92);
			
				
			slight_motion_first_start =1;
																	 
		//	err_code = app_timer_start(m_inuse_100ms_timer_id, INUSE_100ms_TEMP_INTERVAL, NULL); 
			 
			err_code = app_timer_start(m_inuse_100ms_timer_id, INUSE_100ms_TEMP_INTERVAL, NULL);  
			uint32_t app_t3= app_timer_cnt_get();	
//			printf("app_t3=%d\r\n",app_t3);
			
//			nrf_drv_gpiote_in_event_disable(ACC_INT_PIN);
      
			}
			
			printf("ACC_INT\r\n");

}		

static void INUSE_100ms_timeout_handler(void)
{
  	     
	        app_timer_stop(m_inuse_100ms_timer_id);
			    uint32_t app_t5= app_timer_cnt_get();	
			    printf("app_t5=%d\r\n",app_t5);	
	        printf("r\r\n\r\n\r\n");
	
	
	        inuse_100ms_cal++;
					
//	        m_beacon_info[14] = 0;    //RESERVED;  
	     
	
        /**********************ACC****GET**********1****************************/
				KX022_ReadReg(KX022_XHPH,&X_VAL_H);
			  KX022_ReadReg(KX022_XHPL,&X_VAL_L);					
		  	X_VAL = (X_VAL_H<<8)+X_VAL_L ; 
			  X_VAL = (int16_t)(X_VAL/4) ;  //mg;
					
			  KX022_ReadReg(KX022_YHPH,&Y_VAL_H);
			  KX022_ReadReg(KX022_YHPL,&Y_VAL_L);	
        Y_VAL = (Y_VAL_H<<8)+Y_VAL_L ; 
		  	Y_VAL = (int16_t)(Y_VAL/4) ;   //error USE X_VAL ago;
				
   			KX022_ReadReg(KX022_ZHPH,&Z_VAL_H);
			  KX022_ReadReg(KX022_ZHPL,&Z_VAL_L);		
				Z_VAL = (Z_VAL_H<<8)+Z_VAL_L ;
			  Z_VAL = (int16_t)(Z_VAL/4) ;    //
	
//	      printf("acc=%d,%d,%d\r\n",X_VAL,Y_VAL,Z_VAL);
			
				acc_sqrt= (uint16_t)(sqrt((X_VAL*X_VAL)+(Y_VAL*Y_VAL)+(Z_VAL*Z_VAL)));
				acc_level= (uint8_t)(acc_sqrt/8);   //LEVEL: judge state to use later;
				
				if(acc_sqrt >=2000)
				acc_sqrt = 2000;
				
//				m_beacon_info[4] =(m_beacon_info[4]&0xF0) | (KX022_ACC_LEVEL_4BIT_JUDGE(acc_sqrt));  //use 4bit to show it;
				m_beacon_info[4] = acc_level;  //		
//				printf("acc_level=%d\r\n",acc_level);
       /**********************ACC****GET**********2****************************/
			 
			 
			 /**********************ACC****JUDGE**********1****************************/
       //*************max in 1s***************************//
			 if(acc_sqrt>acc_level_max)
			 acc_level_max =acc_sqrt;
			 
			 
			 
			 if((inuse_100ms_cal%5) ==0)   //500MS;
			 {
			 m_beacon_info[12] = (m_beacon_info[12]&0xF0) | ((m_beacon_info[12]&0xF0)>>4); 
			 m_beacon_info[12] = (m_beacon_info[12]&0x0F) | ((m_beacon_info[11]&0x0F)<<4);	  //N-4;
			 m_beacon_info[11] = (m_beacon_info[11]&0xF0) | ((m_beacon_info[11]&0xF0)>>4); 
			 m_beacon_info[11] = (m_beacon_info[11]&0x0F) | ((m_beacon_info[10]&0x0F)<<4);	  //N-3;
			 m_beacon_info[10] = (m_beacon_info[10]&0xF0) | ((m_beacon_info[10]&0xF0)>>4); 
			 m_beacon_info[10] = (m_beacon_info[10]&0x0F) | ((m_beacon_info[9]&0x0F)<<4);	    //N-2;
			 m_beacon_info[9] =	 (m_beacon_info[9]&0xF0)  | ((m_beacon_info[9] & 0xF0)>>4);
	 	   m_beacon_info[9] =  (m_beacon_info[9]&0x0F)  | ((m_beacon_info[8]&0x0F)<<4);     //N-1;
 
			 acc_level_max =0;
			 }
			 
			 
			 
			 m_beacon_info[8] = (m_beacon_info[8]&0xF0) | (KX022_ACC_LEVEL_4BIT_JUDGE(acc_level_max));  //use 4bit to show it;  unit:mg;
			 	 
				
			 
			 
			 
			 /****************************1HZ  Application************1******************/
			if((acc_level<=4) &&(SLIGHT_MOTION_FLAG ==1))  //4*8=32mg;
			 {
			SLIGHT_MOTION_TO_STATIC_CAL++;
//			printf("slight_cal=%d\r\n",SLIGHT_MOTION_TO_STATIC_CAL);
			

			if(slight_motion_to_static_first_start_flag ==0)	
			{
			slight_motion_to_static_first_start_cal = inuse_100ms_cal;
			slight_motion_to_static_first_start_flag =1;
			}
       }
			
			else if((acc_level>8)&&(acc_level<=16)&&(SLIGHT_MOTION_FLAG ==1))  //16*8=128mg;     32*8=256mg;
			{
			SLIGHT_MOTION_TO_STATIC_CAL =0;
			slight_motion_to_static_first_start_flag =0;
			slight_motion_to_static_first_start_cal =0;
			m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x01;   //slight motion;
			m_beacon_info[2] = (m_beacon_info[2]&0x0F)|0x10;   //OPEN  STATUS ;
			}
			
			else if((acc_level>16)&&(SLIGHT_MOTION_FLAG ==1))  //128mg;  to intense motion;
			{
			SLIGHT_MOTION_FLAG	=0;	
			INTENSE_MOTION_FLAG =1;   //become 2Hz;
				
			SLIGHT_MOTION_TO_STATIC_CAL  =0;
			slight_motion_to_static_first_start_flag =0;
			slight_motion_to_static_first_start_cal =0;
			

			m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x02;   //intense motion;
//			printf("large motion");
			}
			
			/**************************1Hz  Analyse cal********************************************************************************/
			// 10*4s=40;	>=30 packets  =static;
			if(((SLIGHT_MOTION_FLAG ==1)&&(inuse_100ms_cal-slight_motion_to_static_first_start_cal>0)&&(inuse_100ms_cal-slight_motion_to_static_first_start_cal ==40)&&(SLIGHT_MOTION_TO_STATIC_CAL >=30))  \
			||	((SLIGHT_MOTION_FLAG ==1)&&(inuse_100ms_cal-slight_motion_to_static_first_start_cal<0)&&((inuse_100ms_cal+(65500-slight_motion_to_static_first_start_cal))==40)&&(SLIGHT_MOTION_TO_STATIC_CAL >=30)))
			{
//			printf("slight motion to static\r\n");
			SLIGHT_MOTION_Before_IDLE_FLAG =1;
			SLIGHT_MOTION_FLAG	=0;
			SLIGHT_MOTION_TO_STATIC_CAL  =0;
			slight_motion_to_static_first_start_flag =0;
			slight_motion_to_static_first_start_cal =0;

			Init_KX022_static_100ms_Setting();
			m_beacon_info[2] = m_beacon_info[2]&0xE0 ;   //intense motion;	
//      active_gpio_change_init();
//      nrf_delay_ms(300);				
			}

			else if(((SLIGHT_MOTION_FLAG ==1)&&(inuse_100ms_cal-slight_motion_to_static_first_start_cal>0)&&(inuse_100ms_cal-slight_motion_to_static_first_start_cal ==40)&&(SLIGHT_MOTION_TO_STATIC_CAL <30))  \
			||	    ((SLIGHT_MOTION_FLAG ==1)&&(inuse_100ms_cal-slight_motion_to_static_first_start_cal<0)&&(inuse_100ms_cal+(65500-slight_motion_to_static_first_start_cal) ==40)&&(SLIGHT_MOTION_TO_STATIC_CAL <30)))
			{
//			printf("keep motion and clear cal\r\n");	
			SLIGHT_MOTION_TO_STATIC_CAL =0;
			slight_motion_to_static_first_start_flag =0;
			slight_motion_to_static_first_start_cal =0;
			m_beacon_info[2] = (m_beacon_info[2]&0x0F)|0x10;   //OPEN  STATUS ;
			} 			
		 /**********************ACC****JUDGE**********2****************************/
		 /****************************1HZ  Application************2******************/
			

			
			
			/****************************2HZ  Application************1******************/
			if((acc_level<=4) &&(INTENSE_MOTION_FLAG ==1))  //4*8=32mg;
			 {
			INTENSE_MOTION_TO_SLIGHT_CAL++;
//			printf("slight_cal=%d\r\n",SLIGHT_MOTION_TO_STATIC_CAL);
			
//	    m_beacon_info[2] = m_beacon_info[2]&0xF0;   //slight motion to static;
			if(intense_motion_to_slight_first_start_flag ==0)	
			{
			intense_motion_to_slight_first_start_cal = inuse_100ms_cal;
			intense_motion_to_slight_first_start_flag =1;
			}
       }
			
			else if((acc_level>16)&&(acc_level<=32)&&(INTENSE_MOTION_FLAG ==1))  //16*8=128mg;     32*8=256mg;
			{
			INTENSE_MOTION_TO_SLIGHT_CAL =0;
			intense_motion_to_slight_first_start_flag =0;
			intense_motion_to_slight_first_start_cal =0;
			m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x02;   //intense motion;
			}
			
			else if((acc_level>32)&&(INTENSE_MOTION_FLAG ==1))  //128mg;  to intense motion;
			{
			INTENSE_MOTION_FLAG	=0;	
			VIOLENT_MOTION_FLAG =1;
				
			INTENSE_MOTION_TO_SLIGHT_CAL  =0;
			intense_motion_to_slight_first_start_flag =0;
			intense_motion_to_slight_first_start_cal =0;
			

			m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x03;   //violent motion;
//			printf("large motion");
			}
			
			/**************************2Hz  Analyse cal********************************************************************************/
			// 10*3s=30;	>=20 packets  =static;
			if(((INTENSE_MOTION_FLAG ==1)&&(inuse_100ms_cal-intense_motion_to_slight_first_start_cal>0)&&(inuse_100ms_cal-intense_motion_to_slight_first_start_cal ==30)&&(INTENSE_MOTION_TO_SLIGHT_CAL >=20))  \
		 ||	 ((INTENSE_MOTION_FLAG ==1)&&(inuse_100ms_cal-intense_motion_to_slight_first_start_cal<0)&&((inuse_100ms_cal+(65500-intense_motion_to_slight_first_start_cal))==30)&&(INTENSE_MOTION_TO_SLIGHT_CAL >=20)))
			{
//			printf("slight motion to static\r\n");
			INTENSE_MOTION_FLAG	=0;
			SLIGHT_MOTION_FLAG	=1;	
				
      INTENSE_MOTION_TO_SLIGHT_CAL =0;
      intense_motion_to_slight_first_start_cal =0; 
      intense_motion_to_slight_first_start_flag =0;

			m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x01;   //violent motion;				
			}

			else if(((INTENSE_MOTION_FLAG ==1)&&(inuse_100ms_cal-intense_motion_to_slight_first_start_cal>0)&&(inuse_100ms_cal-intense_motion_to_slight_first_start_cal ==30)&&(INTENSE_MOTION_TO_SLIGHT_CAL <20))  \
			||	    ((INTENSE_MOTION_FLAG ==1)&&(inuse_100ms_cal-intense_motion_to_slight_first_start_cal<0)&&(inuse_100ms_cal+(65500-intense_motion_to_slight_first_start_cal) ==30)&&(INTENSE_MOTION_TO_SLIGHT_CAL <20)))
			{
//			printf("keep motion and clear cal\r\n");	
      INTENSE_MOTION_TO_SLIGHT_CAL =0;
      intense_motion_to_slight_first_start_cal =0; 
      intense_motion_to_slight_first_start_flag =0;
			} 			
		 /**********************ACC****JUDGE**********2****************************/
		 /****************************2HZ  Application************2******************/
			
			
			
			/****************************5HZ  Application************1******************/
			if((acc_level<=8) &&(VIOLENT_MOTION_FLAG ==1))  //8*8=64mg;
			 {
			VIOLENT_MOTION_TO_INTENSE_CAL++;
//			printf("slight_cal=%d\r\n",SLIGHT_MOTION_TO_STATIC_CAL);
			
//	    m_beacon_info[2] = m_beacon_info[2]&0xF0;   //slight motion to static;
			if(violent_motion_to_intense_first_start_flag ==0)	
			{
			violent_motion_to_intense_first_start_cal = inuse_100ms_cal;
			violent_motion_to_intense_first_start_flag =1;
			}
       }
			
			else if((acc_level>32)&&(VIOLENT_MOTION_FLAG ==1))  //16*8=128mg;     32*8=256mg;
			{
			VIOLENT_MOTION_TO_INTENSE_CAL =0;
			violent_motion_to_intense_first_start_flag =0;
			violent_motion_to_intense_first_start_cal =0;
//			m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x02;   //intense motion;
			}
			
			
			/**************************5Hz Analyse cal********************************************************************************/
			// 10*2s=20;	>=12 packets  =static;
			if(((VIOLENT_MOTION_FLAG ==1)&&(inuse_100ms_cal-violent_motion_to_intense_first_start_cal>0)&&(inuse_100ms_cal-violent_motion_to_intense_first_start_cal ==20)&&(VIOLENT_MOTION_TO_INTENSE_CAL >=12))  \
		 ||	 ((VIOLENT_MOTION_FLAG ==1)&&(inuse_100ms_cal-violent_motion_to_intense_first_start_cal<0)&&((inuse_100ms_cal+(65500-violent_motion_to_intense_first_start_cal))==20)&&(VIOLENT_MOTION_TO_INTENSE_CAL >=12)))
			{
//			printf("slight motion to static\r\n");
			VIOLENT_MOTION_FLAG	=0;
			INTENSE_MOTION_FLAG	=1;	
				
      VIOLENT_MOTION_TO_INTENSE_CAL =0;
      violent_motion_to_intense_first_start_cal =0; 
      violent_motion_to_intense_first_start_flag =0;

      m_beacon_info[2] = (m_beacon_info[2]&0xF0)|0x02;   //intense motion;				
			}

			else if(((VIOLENT_MOTION_FLAG ==1)&&(inuse_100ms_cal-violent_motion_to_intense_first_start_cal>0)&&(inuse_100ms_cal-violent_motion_to_intense_first_start_cal ==20)&&(VIOLENT_MOTION_TO_INTENSE_CAL <12))  \
			||	    ((VIOLENT_MOTION_FLAG ==1)&&(inuse_100ms_cal-violent_motion_to_intense_first_start_cal<0)&&(inuse_100ms_cal+(65500-violent_motion_to_intense_first_start_cal) ==20)&&(VIOLENT_MOTION_TO_INTENSE_CAL <12)))
			{
//			printf("keep motion and clear cal\r\n");	
      VIOLENT_MOTION_TO_INTENSE_CAL =0;
      violent_motion_to_intense_first_start_cal =0; 
      violent_motion_to_intense_first_start_flag =0;
			} 			
		 /**********************ACC****JUDGE**********2****************************/
		 /****************************5HZ  Application************2******************/
			
			
			

			
     /**********************ADC****BAT**********1****************************/
			nrf_drv_adc_buffer_convert(adc_buffer,ADC_BUFFER_SIZE);
			nrf_drv_adc_sample();
     /**********************ADC****BAT**********2****************************/
			
			/**********************LOOP****JUDGE**********1****************************/
			LOOP_IN_STATE = nrf_gpio_pin_read(LOOP_IN_CHECK);
			
			if(LOOP_IN_STATE ==0)  //LOOP CLOSE;
			{
			LOOP_IN_CLOSE_FLAG =1;
			m_beacon_info[7] = m_beacon_info[7]&0x7F;
			}
			else   //OPEN;
			{
			m_beacon_info[7] = (m_beacon_info[7]&0x7F)|0x80;
			}

      if((LOOP_IN_CLOSE_FLAG ==1)&&(LOOP_IN_STATE ==1))	
      {
			LOOP_IN_CLOSE_OPEN_CAL++;
			if(LOOP_IN_CLOSE_OPEN_CAL>0x7F)
			LOOP_IN_CLOSE_OPEN_CAL=0;
			
			LOOP_IN_CLOSE_FLAG =0;
			m_beacon_info[7] = (m_beacon_info[7]&0x80) | LOOP_IN_CLOSE_OPEN_CAL;
			}				
			/**********************LOOP****JUDGE**********2****************************/
			
			
			
		
      
			 /**********************ADV****JUDGE**********1****************************/
//			if((inuse_100ms_cal%1) ==0)  //not every time can fit it;
			sd_ble_gap_adv_stop();   //important;

			////*************************1 Hz*****************************************************///
			if(((inuse_100ms_cal%10) ==0) && (SLIGHT_MOTION_FLAG ==1) && (lf_active_flag ==0))  //1s once time;
			{
			advertising_init();
			sd_ble_gap_tx_power_set((BLE_TX_POWER&0x0F)-6);  //At this place;after ...init();
			advertising_start();
			
			BLE_SEND_TIMES++;
			m_beacon_info[5] = BLE_SEND_TIMES;
			if(BLE_SEND_TIMES>=0xFF)
			BLE_SEND_TIMES =0;
			
			printf("1S\r\n");
		  }
			
			////*************************2Hz*****************************************************///
			if(((inuse_100ms_cal%5) ==0) && (INTENSE_MOTION_FLAG ==1) && (lf_active_flag ==0))  //500ms once time;
			{
			advertising_init();
			sd_ble_gap_tx_power_set((BLE_TX_POWER&0x0F)-6);  //At this place;after ...init();
			advertising_start();
			
			BLE_SEND_TIMES++;
			m_beacon_info[5] = BLE_SEND_TIMES;
			if(BLE_SEND_TIMES>=0xFF)
			BLE_SEND_TIMES =0;
			
			printf("500ms\r\n");
		  }
      /**********************ADV****JUDGE**********2****************************/
			
			
			////*************************5Hz*****************************************************///
			if(((inuse_100ms_cal%2) ==0) && (VIOLENT_MOTION_FLAG ==1) && (lf_active_flag ==0))  //200ms once time;
			{
			advertising_init();
			sd_ble_gap_tx_power_set((BLE_TX_POWER&0x0F)-6);  //At this place;after ...init();
			advertising_start();
			
			BLE_SEND_TIMES++;
			m_beacon_info[5] = BLE_SEND_TIMES;
			if(BLE_SEND_TIMES>=0xFF)
			BLE_SEND_TIMES =0;
			
			printf("200ms\r\n");
		  }
      /**********************ADV****JUDGE**********2****************************/
	
			
			/*******************100ms  adv  3 packets after change to static;*****************/
			
			if((SLIGHT_MOTION_Before_IDLE_FLAG ==1) && (lf_active_flag ==0))   //100ms once time;
			{
			advertising_init();
			sd_ble_gap_tx_power_set((BLE_TX_POWER&0x0F)-6);  //At this place;after ...init();
			advertising_start();
			
			BLE_SEND_TIMES++;
			m_beacon_info[5] = BLE_SEND_TIMES;
			if(BLE_SEND_TIMES>=0xFF)
			BLE_SEND_TIMES =0;
			
			printf("100MS\r\n");
		  }
			
			
			////*************************1/20 Hz*****************************************************///
//			if(((inuse_100ms_cal%10) ==0) && ((SLIGHT_MOTION_FLAG ==0)&&(INTENSE_MOTION_FLAG==0)&&(VIOLENT_MOTION_FLAG ==0)&&(SLIGHT_MOTION_Before_IDLE_FLAG==0)&& (lf_active_flag ==0)))  //2s once time;
//			{
//			advertising_init();
//			sd_ble_gap_tx_power_set((BLE_TX_POWER&0x0F)-6);  //At this place;after ...init();
//			advertising_start();
//			
//			BLE_SEND_TIMES++;
//			m_beacon_info[5] = BLE_SEND_TIMES;
//			if(BLE_SEND_TIMES>=0xFF)
//			BLE_SEND_TIMES =0;
//			
//			printf("20S\r\n");
//		  }
      /**********************ADV****JUDGE**********2****************************/
			
			
			
			/**********************APP TIMER****JUDGE**********1****************************/
			if(((SLIGHT_MOTION_FLAG ==1) || (INTENSE_MOTION_FLAG==1) || (VIOLENT_MOTION_FLAG==1)) && (lf_active_flag ==0))
			{
//			app_timer_stop(m_inuse_5s_timer_id);		
		  err_code = app_timer_start(m_inuse_100ms_timer_id, INUSE_100ms_TEMP_INTERVAL, NULL);  
//		  APP_ERROR_CHECK(err_code);
//			printf("111\r\n");
			}
			
			else if ((SLIGHT_MOTION_FLAG ==0)&&(INTENSE_MOTION_FLAG==0)&&(VIOLENT_MOTION_FLAG ==0)&&(SLIGHT_MOTION_Before_IDLE_FLAG==1) && (lf_active_flag ==0))
			{
			err_code = app_timer_start(m_inuse_100ms_timer_id, INUSE_100ms_TEMP_INTERVAL, NULL); 
			SLIGHT_MOTION_Before_IDLE_CAL++;
			if(SLIGHT_MOTION_Before_IDLE_CAL ==3)
			{
			SLIGHT_MOTION_Before_IDLE_CAL =0;
			SLIGHT_MOTION_Before_IDLE_FLAG =0;
			}
//			printf("222\r\n");
			}	
			
			else if((SLIGHT_MOTION_FLAG ==0)&&(INTENSE_MOTION_FLAG==0)&&(VIOLENT_MOTION_FLAG ==0)&&(SLIGHT_MOTION_Before_IDLE_FLAG==0)&& (lf_active_flag ==0))  //after slight motion to static;
			{
//			sd_ble_gap_adv_stop();
			slight_motion_first_start =0;  // use in active_acc_in_pin_handler();	
			SLIGHT_MOTION_Enter_IDLE_FLAG =1;
			
			acc_level_max =0;	
			voltage_max =0;		
      m_beacon_info[8] = m_beacon_info[8]&0xF0;				
			m_beacon_info[9] = 0;
			m_beacon_info[10] =0;
			m_beacon_info[11] =0;
			m_beacon_info[12] =0;
				
//			active_gpio_change_init();	
//			Init_KX022_static_100ms_Setting();	
				
//			app_timer_stop(m_inuse_100ms_timer_id);	
				
			err_code = app_timer_start(m_inuse_100ms_timer_id, INUSE_5s_TEMP_INTERVAL, NULL); 
			uint32_t app_t4= app_timer_cnt_get();	
			printf("app_t4=%d\r\n",app_t4);
//			err_code = app_timer_start(m_inuse_5s_timer_id, INUSE_5s_TEMP_INTERVAL, NULL); 	
		  printf("5S\r\n");
			}

			
 
			
			
			/**********************APP TIMER****JUDGE**********2****************************/
			if((inuse_100ms_cal%5) ==0)  //Half second counting;
			m_beacon_info[6] = m_beacon_info[6]+1;
			
//			 printf("sss\r\n");
			
			if(inuse_100ms_cal == 65500)  //to be used / in acc also;
			inuse_100ms_cal=0;

			printf("s\r\n");
			
			
}

I think my trouble like this:

https://devzone.nordicsemi.com/f/nordic-q-a/40987/app_timer-hangs

app_timer hangs

Parents
  • Hi,

    I am having a bit of problem understanding the problem. By "Maybe it hangs", you mean that the app_timer no longer fires? Does the whole system "hang"? If so, it is tempting to think that an error_check has been caught. Have you checked that? Also, if you do multiple calls to app_timer* from a interrupt priority it might be that the queue size of 2 is too short. Can you try to increase it?

Reply
  • Hi,

    I am having a bit of problem understanding the problem. By "Maybe it hangs", you mean that the app_timer no longer fires? Does the whole system "hang"? If so, it is tempting to think that an error_check has been caught. Have you checked that? Also, if you do multiple calls to app_timer* from a interrupt priority it might be that the queue size of 2 is too short. Can you try to increase it?

Children
No Data
Related