NRF52832 RTC2

Hi  Nordic:

        We are working on a project, using NRF52832, which has the functions of softdevice+bootloader+ble+dfu, the SDK we use is version 17.0.0,

        and RTC2 is used as a 1ms timer. We found that after running for a period of time, 20 devices A device appears in the RTC2 and cannot generate an interrupt.

       Then we deleted the firmware, using the example of the official RTC2 firmware, the interrupt is also unable to enter, we guessed that there is a problem with the internal crystal oscillator.     

        How do we solve this problem

static const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(2);

static uint8_t isSleep = 0;

volatile static uint32_t time_1ms = 0;
#define time_cb_max 32
static TIME_callback time_cb[time_cb_max]={0};


static void rtc_tick_handler(nrf_drv_rtc_int_type_t int_type)
{
	uint32_t err_code;
    if (int_type == NRF_DRV_RTC_INT_COMPARE0)
    {
//		SEGGER_RTT_printf(0,"1");
//		uint32_t tem1 = NRF_RTC0->COUNTER;
		nrf_drv_rtc_counter_clear(&rtc);
		err_code = nrf_drv_rtc_cc_set(&rtc,NRF_DRV_RTC_INT_COMPARE0,HeartTime_Interval*33,true); APP_ERROR_CHECK(err_code);
		if(isSleep==0){
			time_1ms+=HeartTime_Interval;
			for(int i=0;i<time_cb_max;i++) { //SEGGER_RTT_printf(0,"time_cb[%d]=%d\n",i,time_cb[i]);
				if(time_cb[i]){
					time_cb[i]((uint32_t*)(&time_1ms)); 
				}
			}
//			uint32_t tem2 = NRF_RTC0->COUNTER;
//			if(tem2<tem1) tem2 += 16777216;
//			if(tem2-tem1>0)	SEGGER_RTT_printf(0,"rtc_tick_handler(%d)\n",tem2-tem1);
		}
    }
    else if (int_type == NRF_DRV_RTC_INT_TICK)
    {
//        SEGGER_RTT_printf(0,"NRF_DRV_RTC_INT_TICK(0x%X)\n",NRF_RTC0->COUNTER);
    }
}


uint32_t TIME_GetTicks(void)
{
	return time_1ms;
}

int TIME_Regist(TIME_callback cb)
{
	for(int i=0;i<time_cb_max;i++) {
		if(time_cb[i]==cb) return -2;
		if(time_cb[i]==0){
			time_cb[i] = cb;  //回调函数
			return 0;
		}
	}
	return -1;
}

int TIME_UnRegist(TIME_callback cb)
{
	for(int i=0;i<time_cb_max;i++){
		if(time_cb[i] == cb){
			time_cb[i] = 0;
			return 0;
		}
	}
	return -1;
}

uint32_t rtc_sleep(uint8_t is_wearshoes)
{
	uint32_t tem1 = NRF_RTC0->COUNTER;
	uint32_t ret = 0;
	uint32_t err_code;
	isSleep = 1;

	if(is_wearshoes==0){ err_code = nrf_drv_rtc_cc_set(&rtc,0,StandByPower_Interval * 33,true); APP_ERROR_CHECK(err_code);}
	else { err_code = nrf_drv_rtc_cc_set(&rtc,0,LowPower_Interval * 33,true); APP_ERROR_CHECK(err_code);}
	nrf_drv_rtc_counter_clear(&rtc);
	while(nrf_drv_rtc_counter_get(&rtc) != 0);

	for(int i=0;i<5;i++){
		uint32_t cnt1 = NRF_RTC0->COUNTER;
		nrf_pwr_mgmt_run();
//		idle_state_handle();
		uint32_t cnt2 = NRF_RTC0->COUNTER;
		if(cnt2<cnt1) cnt2 += 16777216;
		if(cnt2-cnt1>32) break;
	}
	
	err_code = nrf_drv_rtc_cc_set(&rtc,0,HeartTime_Interval*33,true); APP_ERROR_CHECK(err_code);
	nrf_drv_rtc_counter_clear(&rtc);
	while(nrf_drv_rtc_counter_get(&rtc) != 0);
	isSleep = 0;
	uint32_t tem2 = NRF_RTC0->COUNTER;
	if(tem2<tem1) tem2 += 16777216;
	ret = (tem2-tem1)/32.768;
	return ret;
}

static void cb_timeeWakeup(uint32_t t)
{
	time_1ms += t;
	//SEGGER_RTT_printf(0,"cb_timeeWakeup(%d)\n",time_1ms);
}


void TIME_Init(void)
{
	uint32_t err_code;
	nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
	config.interrupt_priority = RTC2_IRQ_PRIORITY;												
	config.prescaler = 0;// f(RTC) = 32.768kHZ/(prescaler+1) = 8HZ = 125ms
	err_code = nrf_drv_rtc_init(&rtc, &config, rtc_tick_handler); APP_ERROR_CHECK(err_code);
	
	err_code = nrf_drv_rtc_cc_set(&rtc,NRF_DRV_RTC_INT_COMPARE0,HeartTime_Interval*33,true); APP_ERROR_CHECK(err_code);
	nrf_drv_rtc_counter_clear(&rtc);
	nrf_drv_rtc_enable(&rtc);

	Wakeup_Regist(cb_timeeWakeup);
}

Parents
  • Hi Ben

    You mean to say that out of 20 devices you have one where the RTC doesn't seem to work anymore?

    Are you testing this on a nRF52DK, or are you using some custom hardware?

    Could you try to flash a standard BLE example into the failing board and see if it works, such as ble_app_uart?

    If you can discover and connect to the device without any problems then the 32k clock must be working, since the SoftDevice is not able to function properly without it. 

    Best regards
    Torbjørn

  • Sorry for replying to you only now, the custom hardware we use, the ble example doesn't work either, we don't use an external 32k clock, we use an internal 32k clock, so is the internal 32k clock broken?

  • Hi Ben

    Would you be able to provide me the hardware schematics, and a picture of the affected board?

    On second thought I realized that most of the SDK examples use external 32k crystal by default. Would you be able to run one more test where you make sure that the NRF_SDH_CLOCK_LF_SRC define in sdk_config.h is set to 0?

    Best regards
    Torbjørn

  • Hello ovrebekk

          For the same board, at the beginning, the RTC was interrupted and could not be entered,

    and the ble broadcast did not have a name. After more than ten days, I recharged the device, and

    then burned the program, and the RTC function was normal again. So I haven't tested the ble_app_uart

    example for now. Our hardware is not connected to a 32K external crystal oscillator

          hardware  

             

  • Hi Ben

    Is there any chance that you have an assert or some other error condition in the code that could be causing the device to stop behaving properly? 

    What if you try this very simple example that only toggles P0.17 based on an RTC interrupt?

    283288_rtc_test.zip

    If everything is working correctly you should see the LED turn on and off every second (looking at your schematic it seems you are using P0.17 for the LED). 

    Best regards
    Torbjørn

  • Hello ovrebekk

           Thank you very much for your reply. After the RTC error occurred, we tried to burn our own program

    and the official RTC example. There was no assert or some other error, but the RTC just couldn't enter the

    interrupt. At the same time, the board with RTC exception can be used again。

          and we have no way to test your program for the time being. If it comes later, let's test it again

Reply
  • Hello ovrebekk

           Thank you very much for your reply. After the RTC error occurred, we tried to burn our own program

    and the official RTC example. There was no assert or some other error, but the RTC just couldn't enter the

    interrupt. At the same time, the board with RTC exception can be used again。

          and we have no way to test your program for the time being. If it comes later, let's test it again

Children
  • Hi Ben

    No problem, just let me know when you have been able to test my example. 

    If the interrupt is not firing then the LED will not blink, so it should be very easy to check if the RTC interrupt is OK using that example. 

    Best regards
    Torbjørn

  • Hi ovrebekk

         This situation happened again, and I used your example, 283288_rtc_test, the rtc interrupt is still

    unable to enter, all the rtc can't work, it seems that the internal RC crystal is not working properly. This

    board was working before. I burned the rtc after charging, will the temperature damage the internal RC

    crystal oscillator?

  • Hi Ben

    How do you verify that the interrupt is not entering? 

    Are you connecting the debugger, or checking if the LED is toggling?

    What is the supply voltage on the chip after you have charged? 

    What about during charging, will the supply voltage change?

    Ben_iot said:

    I burned the rtc after charging, will the temperature damage the internal RC

    crystal oscillator?

    Do you know how high the temperature could get?

    As shown here the nRF52832 should be fine with temperatures up to 125C when it is not in use. 

    Could you send me a closeup picture of your board?

    Best regards
    Torbjørn

Related