This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Code only runs in debugging

Hello,

I have nRF52832 with custom board and using SDK15 with Keil uVISION 5. I am working on beacon example and I have modified it to show battery level. I have done necessary changes for SAADC.

I am getting values too but only when I do step by step debugging in keil.

I have declared a variable static uint16_t battVolt_1 after all #include files. If I do not go with step by step debugging, this variable is not getting the value of ADC.

my main function is(from ble_app_beacon example):

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main(void)
{
log_init();
timers_init();
leds_init();
power_management_init();
ble_stack_init();
update_vbatt();
advertising_init();
NRF_LOG_INFO("Beacon example started.");
advertising_start();
nrf_gpio_pin_set(LED_2);
// Enter main loop.
for (;;)
{
idle_state_handle();
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

my update_vbatt function is:

static void update_vbatt(void)
{
    uint16_t vbatt;
    uint16_t battVolt;
    es_battery_voltage_init();
    es_battery_voltage_get(&vbatt); // Get new battery voltage    
    battVolt = (uint16_t)vbatt;
    battVolt_1 = battVolt;             //declared at beginning of code
}

Why is it only working in step by step debug and why not without it? It broadcasts 0x0000 value always when it runs (means not in debug mode)

I am attaching a video too for reference.