Sleep mode configuration

Learn More常见问题解答教程

9 posts / 0 new
最后一篇
Rajapurerohit.
离线
Last seen:2 months 3 weeks ago
加入:2017-04-20 09:17
Sleep mode configuration

Dear Dialog_Support,

我们正在使用两个中断方法开发我们将唤醒设备的应用程序。
1. Using push button interrupt
2.传感器中断[如果传感器中断引脚上的任何活动]

I have referred the ble_sleep_mode example but for my application it not working properly.
我使用以下代码段来配置中断,

static void app_button_press_cb(void)
{
arch_disable_sleep();
// ARCH_FORCE_ACTIVE_MODE();
if (GetBits16(SYS_STAT_REG, PER_IS_DOWN))
{
periph_init();
}

if (arch_ble_ext_wakeup_get())
{
ARCH_SET_SLEEP_MODE(app_default_sleep_mode);
arch_ble_force_wakeup();
ARCH_BLE_EXT_WAKEUP_OFF();
app_easy_wakeup();
}
}

void app_button_enable(void)
{
app_easy_wakeup_set(app_wakeup_cb);
wkupct_register_callback(app_button_press_cb);
wkupct_enable_irq(WKUPCT_PIN_SELECT(GPIO_KEY_PORT, GPIO_KEY_PIN) | WKUPCT_PIN_SELECT(GPIO_I2C_BUZZER_PORT, ACCELEROMETER_INT), // select pin (GPIO_PORT_1, GPIO_PIN_1)
WKUPCT_PIN_POLARITY(GPIO_KEY_PORT, GPIO_KEY_PIN, WKUPCT_PIN_POLARITY_LOW) | WKUPCT_PIN_POLARITY(GPIO_I2C_BUZZER_PORT, ACCELEROMETER_INT, WKUPCT_PIN_POLARITY_LOW), // polarity low
1,// 1事件
40); // debouncing time = 0

}

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)
{
user_app_adv_start();

// Configure wakeup button
app_button_enable();
}
}

Using this i am unable to generate interrupt and wake my device from sleep.
一些随机行为正在发生,就像我只有第一次检测到按钮中断,如果重复第二次,则无法检测到。
与传感器中断相同。
Please help me solve issue.

Thanks and Regards
Rohit

Device:
PM_Dialog
离线
Last seen:9 hours 17 min ago
职员
加入:2018-02-08 11:03
Hi Rajapurerohit,

Hi Rajapurerohit,

Could you please clarify what you want to do with your application? As I can see in your code that you have posted, you call user_app_adv_start() into user_app_adv_undirect_complete() function, so when the advertise is completed (cancelled by your application) you will start advertise again and your device won’t go to sleep mode. So can you please explain what exactly you would like to do? For example you would like to advertise and have the wake up interrupt configured while advertising?
A few reasons why the waking up might fail:
• In user_app_adv_undirect_complete() function you don’t call arch_ble_ext_wakeup_on() function, as the ble_app_sleepmode example of the SDK. This function turns the sleep_ext_force variable to true when the advertising is completed, which is by default false. When the app_button_press_cb() function is triggered by pressing the button, the arch_ble_ext_wakeup_get() returns the default value which is false, so the code into if (arch_ble_ext_wakeup_get()) will not execute. So, I suggest to check that.
•此外,您应该检查唤醒引脚的状态,并确保它们均高(由于您已将唤醒配置为低电平时)。由于两个源中的一个留在中断状态(在您的情况下),因此当另一个中断切换低时,唤醒控制器不会被触发。
•此外,您是否第二次将按钮启用到应用程序代码中?如果它启用了一次,只有第一次可以检测按钮中断。所以在你想从外部中断唤醒之前,你会调用app_button_enable()吗?

Thanks PM_Dialog

Rajapurerohit.
离线
Last seen:2 months 3 weeks ago
加入:2017-04-20 09:17
Hello PM_Dialog,

Hello PM_Dialog,

感谢您的答复。
My requirement is,
1.在Extended_sleep模式下配置设备,当从按钮中断时,传感器中断以及如果在连接后写入特性时,请唤醒。
2.广告和连接是否有可能睡觉?
Secondly want to set device in sleep during advertising but it should display on my mobile application even though it is in sleep.
And sleep if mobile application connects. Is it possible? if yes, which algorithm should i follow .

3. algorithm现在实施的是唤醒设备,只要有按钮或传感器中断,但在有按钮中断时无法唤醒设备,我在我之前的评论中有附加的代码片段。

GPIO Configuration is as follows
GPIO_ConfigurePin(GPIO_KEY_PORT, GPIO_KEY_PIN, INPUT_PULLUP, PID_GPIO, false);
GPIO_EnableIRQ(GPIO_KEY_PORT, GPIO_KEY_PIN, GPIO3_IRQn, true, true, 250);
GPIO_RegisterCallback(GPIO3_IRQn, PushButtonInterruptHandler);

GPIO_ConfigurePin(GPIO_SENSOR_PORT, SENSOR_INT, INPUT_PULLDOWN, PID_GPIO, false);
gpio_enableirq(gpio_sensor_port,sensor_int,gpio2_irqn,false,true,250);
GPIO_RegisterCallback(GPIO2_IRQn, SENSORInterruptHandler);

Thanks and Regards
Rohit

PM_Dialog
离线
Last seen:9 hours 17 min ago
职员
加入:2018-02-08 11:03
Hi Rajapurerohit,

Hi Rajapurerohit,

1、2)广告之间的设备进入睡眠and connection intervals. The device can wake up either from a pre programmed BLE event (an advertising event or a connection event or a kernel timer) or with a wake up interrupt. For example in the advertising case the device will wake up advertise and the will go back to sleep again and it will not advertise until the time elapses for the next advertising interval. I am not able to get what you mean that your device should display on your mobile phone even though it is in sleep. Could you please clarify your question?

3) In the configuration you have posted in your last post, you have configured an interrupt on a GPIO. This interrupt will be executed only when your device is woken up and it is advertising. This configuration isn’t able to wake up the device during sleep, the wake up controller should be used when the device is into sleep mode, in order for an external interrupt to wake it up.

Thanks PM_dialog

PM_Dialog
离线
Last seen:9 hours 17 min ago
职员
加入:2018-02-08 11:03
你必须了解

您将必须了解设备的运行方式,该设备将根据广告间隔唤醒和广告,因此您可以将设备放在永久睡眠中并仅通过按钮或内核计时器唤醒,或者您可以设置标准的广告间隔,以便设备将自动唤醒(后者是从中央发现的唯一途径)。我还提到了您附加的代码实现中未遵循的一些事情:

1. You enable the standard IRQs in the set_pad_functions and in the callbacks you are also mixed up with the wake up interrupt, when you are in sleep mode regarding permanent or wake up automatically those simple gpio interrupts won’t be able to wake up the system, the system wakes up when sleep via the wake up interrupt. Those interrupts will only work while the system is always on.

2. Also after the timer app_adv_data_update_timer_used is called you invoke the stop advertising and then you restart the advertising and then you enable the wake up interrupt, and also you are enabling it wrong (passing wrong parameters) since the you have mixed up the pin parameter with the polarity parameter (please check the parameters that the function accepts or check this forum tickethttps://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bl...)。Additionally when the interrupt occurs from the external source you send a start advertising command while you are still advertising, but you won’t be able to do that ever since you are checking arch_ble_ext_wakeup_get() which will always will return flash since you have never enabled the arch_ble_ext_wakeup_on() (which is something that I’ve already mentioned in previous post).

To conclude, i am not able to figure out what exactly the code that you have attached should do, or what you would like to do, i would suggest to have a look at the ble_app_sleepmode examples and try to understand how exactly the system operates.

Thanks PM_dialog

Rajapurerohit.
离线
Last seen:2 months 3 weeks ago
加入:2017-04-20 09:17
嗨pm_dialog,

嗨pm_dialog,
感谢您的答复。

But i am unable to understand wkupct_enable_irq (); how does it work and what polarity.
In data sheet also there no much explanation. Can you please give me example of two interrupt pins configuration.
来自附带的链接,我也无法清除我的别针中断。
If follow the sleep mode example configuration , i am not able detect both interrupt or it work only with one interrupt second one wont work.
Please help me to solve issue.

Thanks and Regards
Rohit

PM_Dialog
离线
Last seen:9 hours 17 min ago
职员
加入:2018-02-08 11:03
Hi Rajapurerohit,

Hi Rajapurerohit,

I have modified the ble_app_sleepmode example of SDK5.0.4 in order to provide you an example of two interrupt pins configuration. In this example, you are able to wake up your device either with SW2 (GPIO0_6) button2 or with SW3 (GPIO1_1) button, using the DA1458x ProDK. The device advertises for a defined amount of time (APP_ADV_DATA_UPDATE_TO) when it’s powered up. The default value is 10 seconds. After the expiration of the above timeout, and if the device does not enter the connected state, it stops advertising. After that, the device does nothing and waits for an external event to exit the sleeping state. You can wake up the device by pressing one of the two buttons I’ve just referred you. After the button press the device will start to advertise again for the predefined time. You can modify the ble_app_sleepmode example by following the below steps.

1) Define the SW2 (GPIO0_6) button2 in user_periph_setup.h into HW_CONFIG_PRO_DK configuration
#define GPIO_BUTTON_2_PORT GPIO_PORT_0
#define gpio_button_2_pin gpio_pin_6.

2) Reserve the button2. Got to the user_periph_setup.c file and add in GPIO_reservations() function the following code:

RESERVE_GPIO(PUSH_BUTTON, GPIO_BUTTON_2_PORT, GPIO_BUTTON_2_PIN, PID_GPIO);

3)转到user_periph_setup.c和在set_pad_functions()中添加以下代码:

gpio_configurepin(gpio_button_2_port,gpio_button_2_pin,input_pullup,pid_gpio,false);

4) In the sleep_mode.c, replace app_button_enable() function with the below function. The following function sets up both buttons as wake up interrupt.

静态void app_button_enable(void)
{
app_easy_wakeup_set(app_wakeup_cb);
wkupct_register_callback(app_button_press_cb);
wkupct_enable_irq(WKUPCT_PIN_SELECT(GPIO_BUTTON_PORT, GPIO_BUTTON_PIN) | WKUPCT_PIN_SELECT(GPIO_BUTTON_2_PORT, GPIO_BUTTON_2_PIN), // select pin (GPIO_BUTTON_PORT, GPIO_BUTTON_PIN)
wkupct_pin_polarity(gpio_button_port,gpio_button_pin,wkupct_pin_polarity_low)|WKUPCT_PIN_POLARITY(GPIO_BUTTON_2_PORT, GPIO_BUTTON_2_PIN, WKUPCT_PIN_POLARITY_LOW), // polarity low
1,// 1事件
40); // debouncing time = 0
}

If you follow the below steps, you must be able to have two interrupt pins configuration and wake up your device using either of them. Also, I suggest you to check again the three possible reasons that the waking up in your application might fail.

Thanks PM_dialog

Rajapurerohit.
离线
Last seen:2 months 3 weeks ago
加入:2017-04-20 09:17
你好pm_dialog,

你好pm_dialog,
感谢您的答复,
i have changed function and it works well for me.
basically my end goal is to reach following part
1.Be awake after switch was pressed and go back to sleep after 6 seconds if button is not pressed
(motion detected) again
2. Be awake after motion was detected and go back to sleep after 6 seconds if motion is not
再次检测到(切换)
3. Be awake after you received something in connected state and need to buzz. Then go back
to sleep after 6 seconds if motion is not detected (switch pressed)again

我正在使用Timer0和Timer 2用于PWM生成。但如果在上面提到的流程的情况下,那么M不能正确连接设备,并且PWM也不正常工作,因为它总是可以睡眠状态。
你能帮我使用计时器醒来,6秒后睡觉

Thanks and Regards
Rohit

PM_Dialog
离线
Last seen:9 hours 17 min ago
职员
加入:2018-02-08 11:03
Hi Rajapurerohit,

Hi Rajapurerohit,

1、2),我能理解,你想叫醒你p either via a switch button interrupt or via a sensor interrupt and advertise for 6 seconds. After 6 seconds the device should go to sleep and wake up via the next interrupt. Did I understand correctly? In case you want to do that, you should modify the inputs of the wkupct_enable_irq() function in app_button_enable() function. In the example that I have posted, the wkupct_enable_irq() function enable the interrupt GPIO and the polarity of the two buttons. In your case, you should modify the wkupct_enable_irq() as :

wkupct_enable_irq(WKUPCT_PIN_SELECT(GPIO_BUTTON_PORT, GPIO_BUTTON_PIN) | WKUPCT_PIN_SELECT(GPIO_SENSOR_PORT, GPIO_SENSOR_PIN), // select pin (GPIO_BUTTON_PORT, GPIO_BUTTON_PIN)
wkupct_pin_polarity(gpio_button_port,gpio_button_pin,wkupct_pin_polarity_low)|wkupct_pin_polarity(gpio_sensor_port,gpio_sensor_pin,wkupct_pin_polarity_low),//极性低
1,// 1事件
40); // debouncing time = 0

例如,GPIO_SENSOR_PORT和GPIO_SENSOR_PIN。在您的应用程序中,您应该以输入您的GPIO传感器定义。为了宣传6秒,您醒来时,您应该更改广告数据时间的值。请转到user_sleepmode.h文件并将app_addata_update_to定义的值更改为600.此外,我建议您检查传感器的极性以捕获中断并触发唤醒控制器。例如,如果传感器的极性低,并且您将唤醒控制器的极性配置为低电平,则不会捕获中断,并且不会触发唤醒控制器。我在上一篇文章中提供的示例从两个源设置了一个唤醒信号,可以使用该信号并使用传感器的极性使用中断替换按钮。

3) As I have already mentioned in a previous post, when the device is in extended sleep mode you can only wake up from BLE events, when in connection you will wake up and sleep depending on the predefined connection intervals that you have arranged with you master, you can’t just go to permanent sleep for 6 seconds and still be able to maintain a connection. Regarding the timers, when in extended sleep the device will shut down all the peripherals, you are not going to be able to operate with PWM while you are in sleep. Please try to understand how BLE operates.

https://support.dialog-semiconductor.com/forums/post/dialog-smartbond-bl...

Thanks PM_dialog