I have a custom PCBA with which has the flow of:
- Boot
- Advertise some temperature data read from TWI with a 5 second timeout using `ble_adv_fast_timeout`.
- I then set a timer to wake the `app_timer_start(m_awake_timer_id, APP_TIMER_TICKS(SLEEP_IN_MS), NULL);`
And I expect the device to go into sleep whilst its BLE is not advertising. Here's my main.c file:
#include "app_timer.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_crypto_init.h"
#include "nrfx_clock.h"
#include "SEGGER_RTT.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_delay.h"
#include "customble.h"
#include "peripheral.h"
#include "encryption.h"
void timers_init(void)
{
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
}
static void idle_state_handle(void)
{
if (NRF_LOG_PROCESS() == false)
{
nrf_pwr_mgmt_run();
}
}
/**@brief Function for initializing power management.
*/
void power_management_init(void)
{
ret_code_t err_code;
err_code = nrf_pwr_mgmt_init();
APP_ERROR_CHECK(err_code);
}
int main(void)
{
NRF_LOG_INIT(NULL);
NRF_LOG_DEFAULT_BACKENDS_INIT();
ret_code_t reta = nrf_crypto_init();
APP_ERROR_CHECK(reta);
timers_init();
ble_timers_init();
ble_stack_init();
power_management_init();
gap_params_init();
advertising_init();
advertising_start();
for (;;)
{
idle_state_handle();
}
}
and here's the relevant sections of the customble.c code
void awake_timer_handler()
{
NRF_LOG_INFO("Awake and start advertising");
update_advertising_data_while_advertising();
advertising_start();
}
void sleep_timer_handler()
{
NRF_LOG_INFO("asleep");
sd_ble_gap_adv_stop(m_advertising.adv_handle); // i've tried with and without this
// Proceed with setting the device to low power mode
app_timer_start(m_awake_timer_id, APP_TIMER_TICKS(SLEEP_IN_MS), NULL); // 60 seconds
}
void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
NRF_LOG_INFO("BLE EVENT");
switch (ble_adv_evt)
{
case BLE_ADV_EVT_IDLE:
NRF_LOG_INFO("Advertising event: Idle");
sleep_timer_handler();
break;
}
}
I have measured the amps on the device and during advertising it jumps to about 3mA and when it's not advertising (when I thought it would sleep) it's using ~1.48mA. What exactly am I doing wrong here?
I have commented lots of things out, and it's not the TWI causing the issue, it's definitely the BLE. When I comment out starting BLE, I get ~400uA constant.

