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

RTC Compare stops generating interrupts

I'm having trouble using the RTC1 COMPARE function to generate an event/interrupt when the processor has been put to sleep using sd_app_evt_wait().

My configuration is as follows:

  • Using S110 v7.1.0
  • BLE advertising is disabled (to make sleep states more detectable)
  • Softdevice initialized at system boot, using the line SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_16000MS_CALIBRATION, 0);
  • Prescaler for RTC1 is set to 0xFF, which generates 128Hz ticks.
  • Running a custom OS, but making heavy use of softdevice APIs.

The goal is to simply put the processor to sleep and wake up after a specific amount of time by loading the CC[0] and/or [1] register of RTC1 with an appropriate value (in my case, I use 0x80, which should result in a 1Hz interrupt frequency). The RTC code runs exactly as expected without the sd_app_evt_wait() call. The interrupts all go off, and when I inspect the system registers in the debugger (Keil uVision 5.10) I can see that the COUNTER register gets correctly reset by my interrupt handler when the COUNTER value reaches that set in CC[0]. However, when I add the sd_app_evt_wait() call, I see that interrupts are no longer generated by the RTC, and that the COUNTER register in RTC1 goes right past the value set in CC[0].

In fact, what I instead see is that the COUNTER runs up until 0x800 before being reset back to 0 and waking the system up from sleep. More curiously, I found that by simply changing the enum used in SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_16000MS_CALIBRATION, 0); to NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_8000MS_CALIBRATION, I see the counter reset at 0x400 instead, and interrupts trigger twice as frequently. I have gone further and tried some of the other RC-based enums (as I do not have an external 32kHz oscillator on my board), and seemingly the frequency of the interrupts matches the frequency of calibration.

To my understanding, there should be no relationship between the LFCLK source used (as long as it's RC based, anyway) and the COMPARE function of the RTC (other than the obvious small timing inaccuracies, of course).

Parents Reply Children
  • I'm unable to compile and deploy this successfully. The included project doesn't correctly link against the softdevice hex file. I get the following errors when using the provided project

    Rebuild target 'nrf51422_xxac_s110' compiling main.c... ......\main.c(26): error: #5: cannot open source input file "nordic_common.h": No such file or directory #include "nordic_common.h" ......\main.c: 0 warnings, 1 error compiling bsp.c... "no source": Error: #5: cannot open source input file "..........\bsp\bsp.c": No such file or directory ..........\bsp\bsp.c: 0 warnings, 1 error compiling bsp_btn_ble.c... "no source": Error: #5: cannot open source input file "..........\bsp\bsp_btn_ble.c": No such file or directory ..........\bsp\bsp_btn_ble.c: 0 warnings, 1 error compiling ble_advdata.c... "no source": Error: #5: cannot open source input file "............\components\ble\common\ble_advdata.c": No such file or directory ............\components\ble\common\ble_advdata.c: 0 warnings, 1 error compiling ble_advertising.c... "no source": Error: #5: cannot open source input file "............\components\ble\ble_advertising\ble_advertising.c": No such file or directory ............\components\ble\ble_advertising\ble_advertising.c: 0 warnings, 1 error compiling ble_conn_params.c... "no source": Error: #5: cannot open source input file "............\components\ble\common\ble_conn_params.c": No such file or directory ............\components\ble\common\ble_conn_params.c: 0 warnings, 1 error compiling ble_nus.c... "no source": Error: #5: cannot open source input file "............\components\ble\ble_services\ble_nus\ble_nus.c": No such file or directory ............\components\ble\ble_services\ble_nus\ble_nus.c: 0 warnings, 1 error compiling ble_srv_common.c... "no source": Error: #5: cannot open source input file "............\components\ble\common\ble_srv_common.c": No such file or directory ............\components\ble\common\ble_srv_common.c: 0 warnings, 1 error compiling app_uart_fifo.c... "no source": Error: #5: cannot open source input file "............\components\drivers_nrf\uart\app_uart_fifo.c": No such file or directory ............\components\drivers_nrf\uart\app_uart_fifo.c: 0 warnings, 1 error compiling nrf_delay.c... "no source": Error: #5: cannot open source input file "............\components\drivers_nrf\hal\nrf_delay.c": No such file or directory ............\components\drivers_nrf\hal\nrf_delay.c: 0 warnings, 1 error compiling nrf_drv_common.c... "no source": Error: #5: cannot open source input file "............\components\drivers_nrf\common\nrf_drv_common.c": No such file or directory ............\components\drivers_nrf\common\nrf_drv_common.c: 0 warnings, 1 error compiling nrf_drv_gpiote.c... "no source": Error: #5: cannot open source input file "............\components\drivers_nrf\gpiote\nrf_drv_gpiote.c": No such file or directory ............\components\drivers_nrf\gpiote\nrf_drv_gpiote.c: 0 warnings, 1 error compiling pstorage.c... "no source": Error: #5: cannot open source input file "............\components\drivers_nrf\pstorage\pstorage.c": No such file or directory ............\components\drivers_nrf\pstorage\pstorage.c: 0 warnings, 1 error compiling app_button.c... "no source": Error: #5: cannot open source input file "............\components\libraries\button\app_button.c": No such file or directory ............\components\libraries\button\app_button.c: 0 warnings, 1 error compiling app_error.c... "no source": Error: #5: cannot open source input file "............\components\libraries\util\app_error.c": No such file or directory ............\components\libraries\util\app_error.c: 0 warnings, 1 error compiling app_fifo.c... "no source": Error: #5: cannot open source input file "............\components\libraries\fifo\app_fifo.c": No such file or directory ............\components\libraries\fifo\app_fifo.c: 0 warnings, 1 error compiling app_timer.c... "no source": Error: #5: cannot open source input file "............\components\libraries\timer\app_timer.c": No such file or directory ............\components\libraries\timer\app_timer.c: 0 warnings, 1 error compiling app_trace.c... "no source": Error: #5: cannot open source input file "............\components\libraries\trace\app_trace.c": No such file or directory ............\components\libraries\trace\app_trace.c: 0 warnings, 1 error compiling nrf_assert.c... "no source": Error: #5: cannot open source input file "............\components\libraries\util\nrf_assert.c": No such file or directory ............\components\libraries\util\nrf_assert.c: 0 warnings, 1 error compiling retarget.c... "no source": Error: #5: cannot open source input file "............\components\libraries\uart\retarget.c": No such file or directory ............\components\libraries\uart\retarget.c: 0 warnings, 1 error compiling softdevice_handler.c... "no source": Error: #5: cannot open source input file "............\components\softdevice\common\softdevice_handler\softdevice_handler.c": No such file or directory ............\components\softdevice\common\softdevice_handler\softdevice_handler.c: 0 warnings, 1 error assembling arm_startup_nrf51.s... compiling system_nrf51.c... "._build\nrf51422_xxac_s110.axf" - 1 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:02

  • @llyaK: I assumed you used packs for testing. The example I provided doesn't use pack. You can download the SDK from this link.

    Try to compile ble_app_uart example included in the sdk, if it does, you can put the example ble_app_uart - RTC1 into the same place (\examples\ble_peripheral) and compile.

Related