Hi Community!
I am a beginner with NRF and zephyr and currently doing a small project on nrf52832_mdk on zephyr. I want to deep sleep the system (sys_poweroff) when nothing is happening. I followed the poweroff example and its working fine. I have attached a multimeter in paralell to measure current and I can see the current drop when system poweroff smootly.
In my actual project, when I run the sys_poweroff command in main thread after initialization, it gives the expected results. The system shuts down completely and current drops in micro amperes.
int main(void) { printk("initializing the system \n"); int ret; int errorCode = 0; struct sensor_value regValue; /**** Initialize LED****/ ret = led_init(); if (ret != 0) { printk("could not Initialize LED \n"); } /**** Initialize the SC7A20 Sensor ****/ ret = sc7a20_sensor_init(); if (ret != 0) { printk("sensor Initialization failed \n"); errorCode = ERROR_SC7A20_SENSOR; } ret = sc7a20_interrupt_register(); if (ret != 0) { printk("Could not Register Interrupt for SC7A20 \n"); errorCode = ERROR_SC7A20_INTERRUPT; } ret = button_init(); if (ret != 0) { printk("could not Initialize Button \n"); errorCode = ERROR_BUTTON_INIT; } ret = bluetooth_init(&bluetooth_callbacks, &remote_callbacks); if (ret) { printk("bt_enable returned %d", ret); errorCode = ERROR_BLUETOOTH_INIT; } sc7a20_interrupt_controller_thread(); ret = battery_measure_enable(true); if (ret != 0) { printk("Failed initialize battery measurement: %d\n", ret); } sys_poweroff(); }
However, If I run the sys_poweroff in another thread (or in the same main function after some sleep), it doesn't shut system appropriately. The system freezes there and current also remains same (only a little current drops). Here is a minimal code. The main objective is to poweroff the system from another thread. Its just a minimal example of situation where I get the same strange resuls
int main(void) { printk("initializing the system \n"); int ret; int errorCode = 0; struct sensor_value regValue; /**** Initialize LED****/ ret = led_init(); if (ret != 0) { printk("could not Initialize LED \n"); } /**** Initialize the SC7A20 Sensor ****/ ret = sc7a20_sensor_init(); if (ret != 0) { printk("sensor Initialization failed \n"); errorCode = ERROR_SC7A20_SENSOR; } ret = sc7a20_interrupt_register(); if (ret != 0) { printk("Could not Register Interrupt for SC7A20 \n"); errorCode = ERROR_SC7A20_INTERRUPT; } ret = button_init(); if (ret != 0) { printk("could not Initialize Button \n"); errorCode = ERROR_BUTTON_INIT; } ret = bluetooth_init(&bluetooth_callbacks, &remote_callbacks); if (ret) { printk("bt_enable returned %d", ret); errorCode = ERROR_BLUETOOTH_INIT; } sc7a20_interrupt_controller_thread(); ret = battery_measure_enable(true); if (ret != 0) { printk("Failed initialize battery measurement: %d\n", ret); } sys_poweroff(); if (errorCode == 0) { while (1) { battery_ble_notifier(); k_msleep(40000); sys_poweroff(); } } else { led_error_sender(errorCode); }