Reputation: 1
When verifying the low power consumption of NRF52832, softdevice is not used, high-speed and low-speed crystal oscillators are connected externally, and the external crystal oscillator is used as the clock source. Now I have done a short test, the main functions are: a. Turn on HFXO and LFXO and use external crystal oscillators respectively. b. Enable a GPIO to control a Led, turn on the comparison interrupt 0 of rtc0 as a wake-up, set the time to 5 seconds, and set the next timeout time to 5 seconds in the rtc cc0 ISR. c. The while loop in main() contains the following steps: - Turn off HFXO (reduce power consumption) - Enter sleep (for testing, several writing methods are verified here: WFI, WFE, WFE SEV WFE, SEV WFE WFE) - Exit sleep due to rtc interrupt and restart HFXO - For the LED flash obviously, cycle and wait for a period of time, then turn off the LED
Expected result: LED flashes every 5 seconds
I have the following problems:
Here is the code for the test:
static void _rtc0_timer_callback(nrfx_rtc_int_type_t int_type);
#define LED_PIN 13
static void led_init(void)
{
nrf_gpio_cfg_output(LED_PIN);
}
static void led_turn_on(void)
{
nrf_gpio_pin_write(LED_PIN, 0);
}
static void led_turn_off(void)
{
nrf_gpio_pin_write(LED_PIN, 1);
}
void _rtc_timer_start(void)
{
nrfx_rtc_t timer_inst = NRFX_RTC_INSTANCE(0);
nrfx_rtc_config_t timer_cfg = NRFX_RTC_DEFAULT_CONFIG;
// low frequency clock
nrf_clock_lf_src_set((nrf_clock_lfclk_t)1);
nrfx_clock_lfclk_start();
// config
timer_cfg.prescaler = RTC_FREQ_TO_PRESCALER(32768);
nrfx_rtc_init(&timer_inst, &timer_cfg, _rtc0_timer_callback);
nrfx_rtc_counter_clear(&timer_inst);
nrfx_rtc_overflow_enable(&timer_inst, true);
nrfx_rtc_enable(&timer_inst);
}
void _rtc_timer_set_next(uint32_t time_us)
{
uint32_t tick;
tick = (uint32_t)(time_us / (1000000.0 / 32768));
nrfx_rtc_t timer_inst = NRFX_RTC_INSTANCE(0);
tick = (tick + nrfx_rtc_counter_get(&timer_inst));
nrfx_rtc_cc_set(&timer_inst, 0, tick, true);
}
static void _rtc0_timer_callback(nrfx_rtc_int_type_t int_type)
{
// set next timeout
_rtc_timer_set_next(5000000);
}
static void clk_event_handler(nrfx_clock_evt_type_t event)
{
}
int main(void)
{
nrfx_clock_init(clk_event_handler);
nrfx_clock_enable();
nrfx_clock_hfclk_start();
while(nrfx_clock_hfclk_is_running() == false)
{
}
nrfx_clock_lfclk_start();
while(nrfx_clock_lfclk_is_running() == false)
{
}
led_init();
led_turn_off();
_rtc_timer_start();
_rtc_timer_set_next(5000000);
while(1)
{
// Turn off HFXO, switch hfclk to HFINT, to reduce power consumption
nrfx_clock_hfclk_stop();
// Execute following code, Led is always on, and MCU can not enter sleep mode.
// __WFE();
// __SEV();
// __WFE();
// Execute following code, Led is flash every 5 secons, but SEV && SFE may clear any event generated before, which may be useful for wakeuo system to handle appropriate event.
// __SEV();
// __WFE();
// __WFE();
// Execute following code, Led is flash every 5 secons
__WFI();
// Execute following code, Led is always on, and MCU can not enter sleep mode.
// __WFE();
// Turn on the HFXO, and switch HFCLK to it.
// As long as this line is commented out, the above sleep behaviors are in line with expectations.
// But the clock interrupt is enabled, why does it affect the behavior of wfe?
nrfx_clock_hfclk_start();
while(nrfx_clock_hfclk_is_running() == false)
{
}
// 点亮一会Led,使其观察明显
led_turn_on();
for(uint32_t i = 1000000; i > 0; i--)
{
__NOP();
}
led_turn_off();
}
}
Upvotes: 0
Views: 149