Hey guys,
First of all, I'm using the SDK 14.1 with my nRF52832-DK.
I'm trying to get the function app_timer_start()
work with the app_scheduler
.
But the app_timer_start()
function will not be executed right.
In my sdk_config.h
the #define APP_TIMER_CONFIG_USE_SCHEDULER 1
is defined.
But everytime I call the app_timer_start() function, with activating the notification on the bas, to read my batterylevel, the device lost the connection.
I will give you some of my code snippets:
timers_init:
static void timers_init(void)
{
ret_code_t err_code;
err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
// Create security request timer.
err_code = app_timer_create(&m_sec_req_timer_id,
APP_TIMER_MODE_SINGLE_SHOT,
sec_req_timeout_handler);
APP_ERROR_CHECK(err_code);
// Create battery timer.
err_code = app_timer_create(&m_battery_timer_id,
APP_TIMER_MODE_REPEATED,
battery_level_meas_timeout_handler);
read_error(err_code);
APP_ERROR_CHECK(err_code);
}
bas_init:
static void bas_init(void)
{
ret_code_t err_code;
ble_bas_init_t bas_init_obj;
memset(&bas_init_obj, 0, sizeof(bas_init_obj));
bas_init_obj.evt_handler = on_bas_evt;
bas_init_obj.support_notification = true;
bas_init_obj.p_report_ref = NULL;
bas_init_obj.initial_batt_level = 100;
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&bas_init_obj.battery_level_char_attr_md.cccd_write_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&bas_init_obj.battery_level_char_attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&bas_init_obj.battery_level_char_attr_md.write_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&bas_init_obj.battery_level_report_read_perm);
err_code = ble_bas_init(&m_bas, &bas_init_obj);
APP_ERROR_CHECK(err_code);
}
on_bas_evt:
static void on_bas_evt(ble_bas_t * p_bas, ble_bas_evt_t * p_evt)
{
ret_code_t err_code;
switch (p_evt->evt_type)
{
case BLE_BAS_EVT_NOTIFICATION_ENABLED:
// Start battery timer
err_code = app_timer_start(m_battery_timer_id, BATTERY_LEVEL_MEAS_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);
break; // BLE_BAS_EVT_NOTIFICATION_ENABLED
case BLE_BAS_EVT_NOTIFICATION_DISABLED:
err_code = app_timer_stop(m_battery_timer_id);
APP_ERROR_CHECK(err_code);
break; // BLE_BAS_EVT_NOTIFICATION_DISABLED
default:
// No implementation needed.
break;
}
}
main:
int main(void)
{
bool erase_bonds;
// Initialize
log_init();
timers_init();
buttons_leds_init(&erase_bonds);
ble_stack_init();
scheduler_init();
gap_params_init();
gatt_init();
db_discovery_init();
peer_manager_init();
advertising_init();
services_init();
conn_params_init();
saadc_init();
advertising_start(erase_bonds);
// Enter main loop
for (;;)
{
app_sched_execute();
if (NRF_LOG_PROCESS() == false)
{
power_manage();
}
}
}
I can't see what I do wrong here.
Here is the full code: github
Hopefully someone can help me out of it.
Thanks in advance