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

Error to use ble_advertising_advdata_update() in timer callback function

Hello,

I am using nrf52840 and SDK 16.0.0

I have integrated two examples, ble_app_template and nrf_calendar example. Now I have a problem. I wanna update the manufacturer specific data every 1 sec, so I put the advertisement update function(advertisement_update()) inside the callback function so that the advertisement_update() can be called every 1 sec. My code looks like below. (advertising_init() , advertisement_update(), callback function, and main())

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**@brief Function for initializing the Advertising functionality.
*/
static void advertising_init(void)
{
ret_code_t err_code;
ble_advertising_init_t init; // Struct containing advertising parameters
// Build advertising data struct to pass into @ref ble_advertising_init.
memset(&init, 0, sizeof(init));
ble_advdata_manuf_data_t manuf_data; // Variable to hold manufacturer specific data
uint8_t eg_data[] = {0x12, 0x34, 0x56}; // Our data to advertise
manuf_data.company_identifier = 0x0059; // Nordics company ID
manuf_data.data.p_data = eg_data;
manuf_data.data.size = sizeof(eg_data);
init.advdata.p_manuf_specific_data = &manuf_data;
init.advdata.name_type = BLE_ADVDATA_SHORT_NAME; // Use a shortened name
init.advdata.short_name_len = 5; // Advertise only first 8 letters of name
init.advdata.include_appearance = false;
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Problem #1

Whenever I reboot and try to execute nrf_set_callback() inside main(), it stops running and always returns NRF_BREAKPOINT_COND. What more confused me is when I put the advertisement_update() on the just main function (not inside the callback) it updates the data without any error.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
void nrf_cal_set_callback(void (*callback)(void), uint32_t interval)
{
// Set the calendar callback, and set the callback interval in seconds
cal_event_callback = callback;
m_rtc_increment = interval;
m_time += CAL_RTC->COUNTER / 8;
CAL_RTC->TASKS_CLEAR = 1;
CAL_RTC->CC[0] = interval * 8;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Problem #2

When I tried to merge the two examples before, I had to change the RTC setting in nrf_calendar example from RTC0 to RTC2, because RTO0 was already used by SoftDevice in ble_app_template example. I was trying to use RTC1 so I did like below in nrf_calendar.h

Fullscreen
1
2
3
4
#define CAL_RTC NRF_RTC1
#define CAL_RTC_IRQn RTC1_IRQn
#define CAL_RTC_IRQHandler RTC1_IRQHandler
#define CAL_RTC_IRQ_Priority 3
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

but the compile failed like below. I have no idea what that means. I appreciate if you could you explain it to me?

Always thanks to Nordic support team. Thanks !!