Hello,
I am using nRF52832 IC with softdevice and SDK v15.
I wish to make the MCU in sleep mode and then a couple of milliseconds (let's say 250ms) wakes up the MCU. For this purpose, can I use the timer? Or do you have any idea ?
Hello,
I am using nRF52832 IC with softdevice and SDK v15.
I wish to make the MCU in sleep mode and then a couple of milliseconds (let's say 250ms) wakes up the MCU. For this purpose, can I use the timer? Or do you have any idea ?
You'll want to use the RTC — Real-time counter. See the Real Time Counter Example and RTC API documentation.
Can I use it with the softdevice?
I have external xtal. Do I need to use "lfclk"?
In addition, does the resolution is second? I need resolution in milliseconds
Any interrupt will wake the CPU.
"I have external xtal. Do I need to use "lfclk"?"
- Well, yes for the RTC you ned a LF clock source. If you've got a 32kHz crystal you can use the LFXO as the source. .
When I do not use the below code into mine softdevice code, the code crashes at the line "ble_stack_init();"
static void rtc_handler(nrf_drv_rtc_int_type_t int_type) { if (int_type == NRF_DRV_RTC_INT_COMPARE0) { nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT); } else if (int_type == NRF_DRV_RTC_INT_TICK) { nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT); } } /** @brief Function configuring gpio for pin toggling. */ static void leds_config(void) { bsp_board_init(BSP_INIT_LEDS); } /** @brief Function starting the internal LFCLK XTAL oscillator. */ static void lfclk_config(void) { ret_code_t err_code = nrf_drv_clock_init(); APP_ERROR_CHECK(err_code); nrf_drv_clock_lfclk_request(NULL); } /** @brief Function initialization and configuration of RTC driver instance. */ static void rtc_config(void) { uint32_t err_code; //Initialize RTC instance nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG; config.prescaler = 4095; err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler); APP_ERROR_CHECK(err_code); //Enable tick event & interrupt nrf_drv_rtc_tick_enable(&rtc,true); //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds err_code = nrf_drv_rtc_cc_set(&rtc,0,COMPARE_COUNTERTIME * 8,true); APP_ERROR_CHECK(err_code); //Power on RTC instance nrf_drv_rtc_enable(&rtc); }
RTC0 is used by the SoftDevice, RTC1 is used by the app_timer, I suggest you use RTC2 as the RTC instance.
OK, I used the RTC2. However, MCU never wakes up from sleep mode.
What is the state of the RTC2's register after you've configured, enabled, and started it?
What is the state of the RTC2's register after you've configured, enabled, and started it?
actually LED is blinking When the MCU is active. there is no wakeup event occurs When the MCU goes into sleep mode.
What is the state of the RTC2's register after you've configured, enabled, and started it?
yes, enabled and started.
I need the content of the RTC2's registers...
When it is running
When It goes to sleep