DA14585 - Advertises only once on wakeup from sleep

Learn MoreFAQsTutorials

15 posts / 0 new
Last post
MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20
DA14585 - Advertises only once on wakeup from sleep

Hi Dialog Team,

I am working on a custom board with the 'ble_app_nonconn' example in the misc folder in SDk folder. My project requirement is as follows.

  • Go to sleep mode (ARCH_EXT_SLEEP_ON) whenever no ble or other activity.
  • 当外部传感器提供数据时,对话框芯片将唤醒引脚更改中断并使用计时器0开始从传感器中解码数据。
  • Decode the data and update it on the advertisement string.
  • 使用'user_app_adv_start()'启动广告,并启动一个易于计时器,将在6秒内过期。直到那时广告数据被宣传。当App_easy Timer到期时,使用'app_easy_gap_advertise_stop()'停止广告,这将使芯片睡眠。
  • Before stopping advertisement, the wakeup pin will be enabled to wake up the chip from sleep when the next data is ready.

I have mananged to complete the above steps in debugging mode. When I run my program on the RAM and disconnect the debugger the current consumption reduces to 2.4µA. When the external interrupt occurs the current rises to around 50µA and oscillates between 2.4µA to 50µA. ( I guess this is due to the sleep between advertising internvals). So I think the above concept works fine.

But I am stuck at two problems.

1) During sleep mode ( debugger disconnected condition ) when my chip advertises I think it advertises only once. Because I am checking it on a BLE scanner app and I notice that the RSSI value is updated only once. It it only transmitiing once?. If it is transmitting once, then why the current oscillation between 2.4µA to 50µA for the 6 sec duration?

2) The above condition works for a while and all of a sudden, the current increases to 350µA and then there is no advertisement at all. Is my program halted?

Please note that the above two condition occurs only when I disconnect the debugger.

What could cause these two issues during sleep?

问候,

Mark

Device:
PM_Dialog
Offline
Last seen:58 min 11 sec ago
Staff
Joined:2018-02-08 11:03
嗨马克,

嗨马克,

When performing any kind of measurements in sleep mode, you should not run the firmware in debug mode. Otherwise, the device fails to go into sleep mode and the power consumption will be dramatically increased. To do so, my suggestion would be to have the debugger de-attached, as this prevents the system to sleep. Additionally, a very important tip is that in case you are using SPI Flash in your custom board, you should power it down.

Can you please try to debug it furthermore? Please run it in debug mode - power consumption is not important in this step. You mentioned that is advertising once… After the first advertising what does the fw do? The WDOG is enabled or disabled? I would suggest you to have it enabled, otherwise you will not be notified if the fw stucks somewhere. If you are completely sure that the fw is running as expected (no WDOG occurred or NMI), please use the Power Profiler of SmartSnippets Toolbox to check that it is not advertising once.

谢谢,PM_Dialog

MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20
HI PM_Dialog,

HI PM_Dialog,

When running in debug mode, the code advertises properly and the firmware does not get stuck anywhere. I ran the code in debug mode for more than an hour and it works fine. When I disconnect the debugger and run it, the problem ( as mentioned in the first post) occurs.

I do have another doubt. Does your example code 'ble_app_nonconn' in the 'misc' folder support extended sleep mode?. Because it works properly when connected in debugging mode. But when i disconnect the debugger the problem starts.

我是广告6秒钟并停止它。但它仅广告一次,但整个6秒内的当前消耗量有振荡。这意味着它在广告间隔之间唤醒,但为什么不发送数据包。?

问候,

Mark

PM_Dialog
Offline
Last seen:58 min 11 sec ago
Staff
Joined:2018-02-08 11:03
嗨马克,

嗨马克,

The ble_app_nonconn project of the SDK6.0.12 does not support sleep mode by default. However, you can change the sleep mode configuration. Since it’s a custom code and custom board, would it be possible to share the changes you have done in order to configure it in sleep mode? Another option to start investigating which is the route cause might be to start toggling a GPIO or printing some debugging messages, as the firmware gests stuck only in non-debug mode. In debug mode, I assume that you have the WDOG enabled..

谢谢,PM_Dialog

MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20
Hi PM_Dialog,

Hi PM_Dialog,

我的固件不会被卡住。它仅在整个6秒持续时间传输单个广告。但是在调试模式下,它会在6秒持续时间传输4到5次。为什么它只在非调试模式中传输一次?是影响BLE广告的睡眠模式吗?

For sleep mode i have made the following changes.

static const sleep_state_t app_default_sleep_mode = ARCH_EXT_SLEEP_ON;

I stopped the advertisement after 6 seconds and my chip goes into extended sleep.

问候,

Mark

PM_Dialog
Offline
Last seen:58 min 11 sec ago
Staff
Joined:2018-02-08 11:03
嗨马克,

嗨马克,

Not sure what happen since it is a custom board/code. Can you please use the arch_printf() in the user_app_adv_start() and in the user_app_adv_nonconn_complete()? Also, can you please send me a screenshot from the Power Profiler? When the debugger is attached and de-attached.

谢谢,PM_Dialog

MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20
Hi ,

Hi ,

I dont have an option to print messages in my custom board. I am using a multimeter to measure the current consumption.

我认为问题在于calling the user_app_adv_start() function when i am ready to advertise again.

I have attached the code below for your refernce.

void user_app_adv_start(void) { struct gapm_start_advertise_cmd *cmd = app_easy_gap_non_connectable_advertise_get_active(); // Store initial advertising data and length initial_adv_data_len = cmd->info.host.adv_data_len; memcpy(initial_adv_data, cmd->info.host.adv_data, initial_adv_data_len); // Store initial scan response data and length initial_scan_rsp_data_len = cmd->info.host.scan_rsp_data_len; memcpy(initial_scan_rsp_data, cmd->info.host.scan_rsp_data, initial_scan_rsp_data_len); //changed // Initialize data data_init(); // Load advertising data and length cmd->info.host.adv_data_len = user_adv_data_len; memcpy(cmd->info.host.adv_data, user_adv_data, user_adv_data_len); // Load scan response data and length cmd->info.host.scan_rsp_data_len = user_scan_rsp_data_len; memcpy(cmd->info.host.scan_rsp_data, user_scan_rsp_data, user_scan_rsp_data_len); //arch_set_extended_sleep(true); app_easy_gap_non_connectable_advertise_start(); //Schedule the next advertising data update app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb); } static void data_init() { // Load initial advertising data and length user_adv_data_len = initial_adv_data_len; memcpy(user_adv_data, initial_adv_data, user_adv_data_len); // Load initial scan response data and length user_scan_rsp_data_len = initial_scan_rsp_data_len; memcpy(user_scan_rsp_data, initial_scan_rsp_data, user_scan_rsp_data_len); //load predefined data user_adv_data_len = ADV_DATA_LEN ; user_scan_rsp_data_len = SCAN_RSP_DATA_LEN ; user_adv_data[12] = 7; user_adv_data[13] = txBuffer[1]; user_adv_data[14] = txBuffer[2]; user_adv_data[15] = txBuffer[3]; user_adv_data[16] = txBuffer[4]; user_adv_data[17] = txBuffer[5]; user_adv_data[18] = txBuffer[6]; user_adv_data[19] = txBuffer[9]; if(user_adv_data[13]==0){ user_adv_data[13]=0xff; } if(user_adv_data[14]==0){ user_adv_data[14]=0xff; } if(user_adv_data[15]==0){ user_adv_data[15]=0xff; } if(user_adv_data[16]==0){ user_adv_data[16]=0xff; } if(user_adv_data[17]==0){ user_adv_data[17]=0xff; } if(user_adv_data[18]==0){ user_adv_data[18]=0xff; } if(user_adv_data[19]==0){ user_adv_data[19]=0xff; } }

MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20
Hi PM_Dialog,

Hi PM_Dialog,

As u suggested, i pulled down a GPIO onperiph_init()and pulled it high before going to sleep beforearch_goto_sleep(sleep_mode)in arch_main.c. I attached the screenshot of oscilloscope output. The problem I am facing is, when I call user_app_adv_start(), the chip is transmitting the data only once. I confirmed this by looking at the RSSI value on the BLE scanner app in android. I have attached the sample code also.

正如我对我的产品的紧急演示一样,我已经改变了广告间隔到200ms和以某种方式通过调用'user_app_adv_start()'和1秒后我停止它以及在我打电话的广告完整功能之后宣传数据。user_app_adv_start()'再次。我在我的应用中重复了6秒钟,我正在获得多面广告命中。每次我打电话'user_app_adv_start()',我在我的应用程序中只有1个点击,直到我停止广告并再次调用它。

Why does 'user_app_adv_start()' advertising the data only once?

你能请分享我一个信标dat的示例代码吗a which wakes up on an external interrupt and modifies the advertising string and transmits it and goes to sleep.

问候,

Mark

Attachment:
PM_Dialog
Offline
Last seen:58 min 11 sec ago
Staff
Joined:2018-02-08 11:03
嗨马克,

嗨马克,

Let me check it and I'll get back to you.

谢谢,PM_Dialog

PM_Dialog
Offline
Last seen:58 min 11 sec ago
Staff
Joined:2018-02-08 11:03
嗨马克,

嗨马克,

The arch_main.c is SDK file and it is highly recommend NOT modifying any SDK file. All the modifications should be done in the application layer, in the filed that start with user_ . All the other files as SDK related and if any of them is modified we cannot guarantee that the application will work correctly. The SDK should be used as it is provided by dialog without any other modification.

Regarding you source code I am not able to compile it as I am getting couple of errors. Please see below a diff file for how to stop non-connectable advertising, put the device in sleep mode and wake it up. My recommendation would be to start with ble_app_sleepmode example of the SDK which contains advertising data update as well. How you would like to build the application and how to update the beacon data is up to you. Please follow the steps in the ble_app_sleepmode example of the SDK.

diff - git /项目/ target_apps / ble_examples /祝福_app_sleepmode/src/config/user_callback_config.h b/projects/target_apps/ble_examples/ble_app_sleepmode/src/config/user_callback_config.h index e61bd1b..060eab8 100644 --- a/projects/target_apps/ble_examples/ble_app_sleepmode/src/config/user_callback_config.h +++ b/projects/target_apps/ble_examples/ble_app_sleepmode/src/config/user_callback_config.h @@ -54,8 +54,8 @@ static const struct app_callbacks user_app_callbacks = { .app_on_update_params_rejected = NULL, .app_on_update_params_complete = NULL, .app_on_set_dev_config_complete = default_app_on_set_dev_config_complete, - .app_on_adv_nonconn_complete = NULL, - .app_on_adv_undirect_complete = user_app_adv_undirect_complete, + .app_on_adv_nonconn_complete = user_app_adv_nonconn_complete, + .app_on_adv_undirect_complete = NULL, .app_on_adv_direct_complete = NULL, .app_on_db_init_complete = default_app_on_db_init_complete, .app_on_scanning_completed = NULL, diff --git a/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.c b/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.c index c4b605e..bf18b3c 100644 --- a/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.c +++ b/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.c @@ -240,8 +240,10 @@ void user_app_adv_start(void) // Schedule the next advertising data update app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb); - struct gapm_start_advertise_cmd* cmd; - cmd = app_easy_gap_undirected_advertise_get_active(); +// struct gapm_start_advertise_cmd* cmd; +// cmd = app_easy_gap_undirected_advertise_get_active(); + + struct gapm_start_advertise_cmd *cmd = app_easy_gap_non_connectable_advertise_get_active(); // Add manufacturer data to initial advertising or scan response data, if there is enough space app_add_ad_struct(cmd, &mnf_data, sizeof(struct mnf_specific_data_ad_structure), 1); @@ -249,7 +251,8 @@ void user_app_adv_start(void) // Set extended sleep with OTP copy during advertising arch_set_extended_sleep(true); - app_easy_gap_undirected_advertise_start(); + //app_easy_gap_undirected_advertise_start(); + app_easy_gap_non_connectable_advertise_start(); } void user_app_connection(uint8_t connection_idx, struct gapc_connection_req_ind const *param) @@ -312,11 +315,13 @@ static void app_button_press_cb(void) */ static void app_wakeup_cb(void) { - // If state is not idle, ignore the message - if (ke_state_get(TASK_APP) == APP_CONNECTABLE) - { - user_app_adv_start(); - } +// // If state is not idle, ignore the message +// if (ke_state_get(TASK_APP) == APP_CONNECTABLE) +// { +// user_app_adv_start(); +// } + + user_app_adv_start(); } /** @@ -335,9 +340,9 @@ static void app_button_enable(void) 40); // debouncing time = 0 } -void user_app_adv_undirect_complete(uint8_t status) +void user_app_adv_nonconn_complete(uint8_t status) { - // Disable wakeup for BLE and timer events. Only external (GPIO) wakeup events can wakeup processor. + // Disable wakeup for BLE and timer events. Only external (GPIO) wakeup events can wakeup processor. if (status == GAP_ERR_CANCELED) { arch_ble_ext_wakeup_on(); @@ -347,6 +352,18 @@ void user_app_adv_undirect_complete(uint8_t status) } } +//void user_app_adv_undirect_complete(uint8_t status) +//{ +// // Disable wakeup for BLE and timer events. Only external (GPIO) wakeup events can wakeup processor. +// if (status == GAP_ERR_CANCELED) +// { +// arch_ble_ext_wakeup_on(); + +// // Configure wakeup button +// app_button_enable(); +// } +//} + void user_app_disconnect(struct gapc_disconnect_ind const *param) { // Cancel the parameter update request timer diff --git a/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.h b/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.h index 8c33892..acae900 100644 --- a/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.h +++ b/projects/target_apps/ble_examples/ble_app_sleepmode/src/user_sleepmode.h @@ -116,7 +116,7 @@ void user_app_connection(uint8_t connection_idx, * @return void **************************************************************************************** */ -void user_app_adv_undirect_complete(uint8_t status); +//void user_app_adv_undirect_complete(uint8_t status); /** **************************************************************************************** @@ -141,6 +141,8 @@ void user_catch_rest_hndl(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id); + +void user_app_adv_nonconn_complete(uint8_t status); /// @} APP

谢谢,PM_Dialog

MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20
Hi PM_Dialog,

Hi PM_Dialog,

1) What kind of errors are u getting when u compile my code?.

2) I modified your arch_main.c file because, when my sensor sends an interrupt I have to wait around 20ms for getting the data, but if I dont wait my code will go back into sleep and I will miss the data. That's why I modified the arch_main.c file to wait till I get the data out and then put the chip to sleep. How to prolong the wake time of the chip?. Can you suggest an idea for that?.

3) When I start my advertising, most of the code content that I added to arch_main.c will not execute because I am checking for conditions in the main loop and I will not execute it while I am advertising. Why is that affecting your sdk and advertising sequences?.

4)当我收到中断时,直到我从传感器处理数据时,我就不会启动广告。在我收到数据后,我将开始广告,我相信我的代码都不会在广告期间运行。那么为什么这对SDK给出了任何问题?

谢谢,

Mark

MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20
Hi PM_Dialog,

Hi PM_Dialog,

Please support me on the above points. As you suggested I have started working on the sleepmode project in ble_examples. My biggest doubt is when my external sensor gives an interrupt and gives the data only after 20ms, how do I have to prevent the chip from going into sleep for that 20ms after I had woken up from sleep.

问候,

Mark

PM_Dialog
Offline
Last seen:58 min 11 sec ago
Staff
Joined:2018-02-08 11:03
嗨马克,

嗨马克,

Please find attached a log file with the errors from the Keil IDE. It would be very helpful to indicate the SDK version that you are using. Not sure about the SDK version but we strongly recommend using the latest version (SDK6.0.12).

  • Remove all the unused code lines. This makes the thing difficult to go through the code and understand the implementation.
  • All the modifications and the development should be done in the APPLICATION layer. None of the SDK should be modified. If you modify the SDK files, we cannot provide any support.
  • Please remove all the code snippets from the SDK files, like in arch_main.c.
  • All the application layer files start with “ user_ “.
  • Please provide me a working project to add it under projects\target_apps\misc SDK directory and indicate the SDK version.
  • In order to start debugging it, I should copy paste the project under the aforementioned path, open it and compile it.
  • Keep in mind that you have a custom board, so I will try to replicate the issue in our Pro Development Board.
  • When in sleep mode, the device will go into sleep mode between advertising intervals (or connection intervals in case of connectable advertising). All the peripheral domains, including the I2C are powered down. When the sensor has data to send, you should wake up the device first thought the wake-up controller.
  • My recommendation is to start developing in the ble_app_sleepmode example. I have provided you a diff file with the changes required.
  • The WDOG should be enabled, otherwise you will not be notified if the application gets stuck.
  • If you run the default ble_app_sleepmode example of the SDK, are you able to stop advertising and put the device into sleep mode?

谢谢,PM_Dialog

Attachment:
MarkDsylva_2277
Offline
Last seen:5 days 14 hours ago
Joined:2019-06-19 04:20

Hi PM_Dialog,

在添加外部32kHz晶体振荡器后,该问题被整理出来。

It seems that that the ble_app_sleepmode code is unstable without the 32Khz crystal. But your datasheets say that this 32Khz is optional which is very much misleading. Please correct the datasheets or it may mislead others too. I have spent 3-4 months on this issue and had no clue it was due to the external crystal.

Any way, thank you for your online support.

问候,

Mark

PM_Dialog
Offline
Last seen:58 min 11 sec ago
Staff
Joined:2018-02-08 11:03
嗨马克,

嗨马克,

很高兴你找到了工作。这是铁饼sed over our previous conference calls. Thanks for your indication too.

问候,PM_Dialog