Hi everyone,
I am facing a kind of a strange problem. I want the system to enters system OFF mode when a certain pins goes to LOW. For that reason I have include code section below inside the main for(;;) loop.
When the WC_CHG pin goes to LOW I want the system to enter the system OFF mode. The strange thing is that while advertising and the WC_CHG pin goes to LOW the system normaly enters system OFF mode but when the peripheral is get connected with the central the system won't enter system OFF mode anymore. I noticed that when I add the NRF_LOG_INFO("Print here"); line the code works fine and I cannot understand how does it related with my problem. It is like the NRF_LOG_INFO() makes the loop runs normally.. Also I tried to add some delay but it doesn't work. Any advice?
nrf_gpio_cfg_input(WC_CHG, NRF_GPIO_PIN_PULLUP);
for (;;) {
int charging = nrf_gpio_pin_read(WC_CHG);
if (!charging) {
UN_state = BLE_STATE_CHARGING;
charging_state(UN_state);
//nrf_delay_ms(100); // na - some delay to run the function above before go to system OFF
sleep_mode_enter();
}
// Enter system On sleep mode
idle_state_handle(); // na - The Power Management library is safer to use than the inline functions __SEV, __WFE, __WFI especially when SoftDevice is used.
NRF_LOG_INFO("Print here");
}
Also I have a second problem. Before the system goes to system OFF mode the two NRF_LOG_INFO are not printed.
NRF_LOG_INFO("Stop advertising and go to sleep.");
NRF_LOG_INFO("Wait for TAP interrupt or STEP detection");
I tried to add some delay before sleep_mode_enter(); but did not work.. Any advice?
case BLE_ADV_EVT_IDLE:
NRF_LOG_INFO("Stop Advertising event received %d", BLE_ADV_EVT_IDLE);
NRF_LOG_INFO("Previous State %d", UN_state); // na
if (UN_state == BLE_STATE_ADVERTISING) {
NRF_LOG_INFO("Stop advertising and go to sleep.");
NRF_LOG_INFO("Wait for TAP interrupt or STEP detection");
UN_state = BLE_STATE_SLEEP;
nrf_delay_ms(100);
sleep_mode_enter();
} else if (UN_state == BLE_STATE_OFFLINE) {
NRF_LOG_INFO("State %d", UN_state);
ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST); // na - Restart advertising
}
break;
default:
break;
Thanks in advance
Nick