BLE DEVICE I AM USING IS NOT GOING TO SLEEP WHY IT IS NOT GOING TO SLEEP .THE COMPONENTS THT ARE CONECTED TO THE DEVICE ARE INA226AIDGST,WS2812B-MINI,MDBT50Q-1MV2, THESE ARE THE COMPONENTS I AM USING AND ALSO THE DEVICE IS NOT GOING TO SLEEP WHY

int main(void) {
bool erase_bonds;
// Initialize.
log_init();
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
// NRF_LOG_INFO("before the blestack function.");
ble_stack_init();
ret_code_t err_code = sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
APP_ERROR_CHECK(err_code);
gap_params_init();
gatt_init();
services_init();
advertising_init();
err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, -8);
APP_ERROR_CHECK(err_code);
conn_params_init();
peer_manager_init();
nrf_delay_ms(200);
//twi_init();
ws2812_init();
//ina226_init();
application_timers_start();
advertising_start(erase_bonds);
NRF_LOG_INFO("After all initialization");
//sht41_read();
//process_data();
int cnt = 0;
bool interval_changed = false;
for (;;) {
if (updtmrexp) {
//check_why_i_woke_up();
updtmrexp = false;
g_do_sensor_read = false;
if (tx_enable == 1) {
NRF_LOG_INFO("TX enabled -> reading sensor");
//sht41_read();
//battery_level_update(70);
//process_data();
} else {
NRF_LOG_WARNING("TX disabled -> skipping sensor read");
}
if (g_interval_changed) {
g_interval_changed = false;
// Prevent invalid interval (safety guard)
if (new_tx_interval == 0)
new_tx_interval = 8; // fallback to 8 seconds
tx_interval = new_tx_interval;
NRF_LOG_INFO("Applying new tx_interval: %d sec", tx_interval);
uint32_t ticks = APP_TIMER_TICKS(tx_interval * 1000UL);
ret_code_t err;
// === SAFE STOP ===
err = app_timer_stop(m_timer_id);
if (err != NRF_SUCCESS && err != NRF_ERROR_INVALID_STATE) {
NRF_LOG_WARNING("app_timer_stop() failed: 0x%08X", err);
// Do NOT reset device in production
}
// === SAFE RESTART ===
err = app_timer_start(m_timer_id, ticks, NULL);
if (err != NRF_SUCCESS) {
NRF_LOG_ERROR("app_timer_start() failed: 0x%08X", err);
// Optional: try again once
nrf_delay_ms(10);
err = app_timer_start(m_timer_id, ticks, NULL);
}
if (err == NRF_SUCCESS) {
NRF_LOG_INFO("Timer successfully restarted with new interval");
} else
NRF_LOG_ERROR("Failed to restart timer!");
}
}
ws2812_set_color(100,0,0); // Cyan
idle_state_handle();
}
}

void check_why_i_woke_up(void) {
for (uint8_t i = 0; i < 48; i++) {
if (NVIC_GetPendingIRQ((IRQn_Type)i)) {
NRF_LOG_INFO("Woke up due to IRQ ID: %d", i);
}
}
}

void nrf_pwr_mgmt_run(void)
{
//__set_FPSCR(__get_FPSCR() & ~(0x0000001F));
// (void) __get_FPSCR();
// NVIC_ClearPendingIRQ(FPU_IRQn);
//__disable_irq();

//ws2812_set_color(0,0,0);
// nrf_delay_ms(300);
PWR_MGMT_FPU_SLEEP_PREPARE();
// ws2812_set_color(0,0,100);
//nrf_delay_ms(300);
PWR_MGMT_SLEEP_LOCK_ACQUIRE();
//ws2812_set_color(100,0,0);
//nrf_delay_ms(300);
PWR_MGMT_CPU_USAGE_MONITOR_SECTION_ENTER();
//ws2812_set_color(100,100,100);
//nrf_delay_ms(300);
// ws2812_set_color(150,150,150);
// cnt=10000;
//while(cnt--);
PWR_MGMT_DEBUG_PIN_SET();
//ws2812_set_color(150,150,0);
// nrf_delay_ms(300);
// ws2812_set_color(150,150,0);
// cnt=10000;
//while(cnt--);

// Wait for an event.
#ifdef SOFTDEVICE_PRESENT
if (nrf_sdh_is_enabled())
{
ret_code_t ret_code = sd_app_evt_wait();
// ws2812_set_color(0,100,100);
//nrf_delay_ms(300);
ASSERT((ret_code == NRF_SUCCESS) || (ret_code == NRF_ERROR_SOFTDEVICE_NOT_ENABLED));
UNUSED_VARIABLE(ret_code);
check_why_i_woke_up();
// NRF_LOG_INFO("AFTER NRF SD APP EVENT WAIT");
ws2812_set_color(100,0,0);
//nrf_delay_ms(600);
}
else
#endif // SOFTDEVICE_PRESENT
{
// Wait for an event.
__WFE();
// Clear the internal event register.
__SEV();
__WFE();
}
NRF_LOG_INFO("after if else of the nrf_sdh_is_enabled");
NRF_LOG_FLUSH();
PWR_MGMT_DEBUG_PIN_CLEAR();
PWR_MGMT_CPU_USAGE_MONITOR_SECTION_EXIT();
PWR_MGMT_SLEEP_LOCK_RELEASE();
}

THIS IS THE CODE PLEASE SOME BODY HELP WITH THIS

Parents Reply Children
Related