亲爱的Dialog_Support,
We are developing application where we are going to wake up device using two interrupt method.
1. Using push button interrupt
2. Sensor interrupt [If any activity on sensor interrupt pin]
I have referred the ble_sleep_mode example but for my application it not working properly.
I have used following snippet to config interrupt,
静态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_plect(gpio_key_port,gpio_key_pin)| wkupct_pin_select(gpio_i2c_buzzer_port,Accelerometer_int),//选择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 event
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.
如果状态= = GAP_ERR_CANCELED)
{
user_app_adv_start();
//配置唤醒按钮
app_button_enable();
}
}
Using this i am unable to generate interrupt and wake my device from sleep.
Some random behavior is happening, like only first time i am able to detect push button interrupt and if repeat for 2nd time fail to detect.
Same with sensor interrupt.
Please help me solve issue.
谢谢并恭祝安康
Rohit
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?
醒来可能失败的几个原因:
• 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.
• Also, you should check the state of your wake up pins and make sure that they are both high (since you have configured the wake up to be triggered when low). Since if one of the two sources remain in interrupt state (low in your case) then the wake up controller won’t be triggered when the other interrupt toggles low.
• In addition, do you enable your button into your application code, the second time? If it’s enabled once, only the first time you will be able to detect the push button interrupt. So do you invoke the app_button_enable() before you would like to wake up from an external interrupt?
Thanks PM_Dialog
你好pm_dialog,
Thank you for the response.
My requirement is,
1.Configure device in extended_sleep mode and wake up when there is interrupt from button, sensor interrupt and if we write into characteristic after connection.
2. Is it possible to sleep while advertising and connection ?
其次,希望在广告期间在睡眠中设置设备,但它应该在我的移动应用程序上显示,即使它在睡眠状态。
如果移动应用程序连接,则睡眠。是否有可能?如果是,我应该遵循哪种算法。
3.Algorithm implemented right now is wake up device whenever there is button or sensor interrupt but not able to wake up device when there is button interrupt and i have attached code snippet in my previous comment.
GPIO配置如下
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);
谢谢并恭祝安康
Rohit
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)在您在上一篇文章中发布的配置中,您已在GPIO上配置了中断。此中断将仅在您的设备唤醒时执行,并且它是广告。此配置无法在睡眠期间唤醒设备,当设备进入睡眠模式时,应使用唤醒控制器,以便外部中断唤醒它。
谢谢pm_dialog.
You will have to understand how the device operates, the device is going to wake up and advertising according to the advertising interval, so you can either place the device in permanent sleep and wake up only via a push button or a kernel timer or you can set a standard advertising interval so that the device will wake up automatically (the latter is the only way to be discoverable from a central). I've also mentioned a few things that you didn't follow in the code implementation that you have attached:
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-semicondiondiondum/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.
谢谢pm_dialog.
Hi PM_dialog,
Thank you for the response.
但我无法理解wkupct_enable_irq();它是如何工作和什么极性。
In data sheet also there no much explanation. Can you please give me example of two interrupt pins configuration.
From attached link also i am not able to clear my pins interrupt.
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.
请帮我解决问题。
谢谢并恭祝安康
Rohit
Hi Rajapurerohit,
我已经修改了SDK5.0.4的BLE_APP_SLEEPMODE示例,以便为您提供两个中断引脚配置的示例。在此示例中,您可以使用DA1458x Prodk使用SW2(GPIO0_6)按钮2或使用SW3(GPIO1_1)按钮唤醒您的设备。设备通电时,该设备已广告已定义的时间(App_add_data_update_to)。默认值为10秒。在上述超时到期后,如果设备未进入连接状态,则会停止广告。之后,该设备无能为力并等待外部事件以退出睡眠状态。您可以通过按我刚刚提到您的两个按钮之一唤醒设备。按钮按下设备后,将开始再次通告预定义的时间。您可以按照以下步骤修改BLE_APP_SLEEPMODE示例。
1)将user_periph_setup.h中的sw2(gpio0_6)按钮2定义为hw_config_pro_dk配置
#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) Go to the user_periph_setup.c and add in the set_pad_functions() function the following code:
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.
static 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),//极性低
1 / / 1 event
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.
谢谢pm_dialog.
Hello PM_dialog,
Thank you for the response,
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
(检测到的运动)再次
2.在检测到运动后醒来,6秒后恢复睡眠,如果动作不是
detected (switch pressed)again
3. Be awake after you received something in connected state and need to buzz. Then go back
6秒后睡觉,如果没有检测到动作(切换)再次
And i am using timer0 and timer 2 for pwm generation. but in if write above mentioned flow then m not able to connect device properly and pwm also not working properly as it is always going to sleep state.
Can you please help me to use timer for wake up and goto sleep after 6sec
谢谢并恭祝安康
Rohit
Hi Rajapurerohit,
1,2)由于我能够理解,您希望通过交换机按钮中断或通过传感器中断醒来,并通过传感器中断并宣传6秒。6秒后,设备应睡觉并通过下一个中断唤醒。我明白了吗?如果您想要这样做,则应在App_Button_Enable()函数中修改WKUPCT_ENABLE_IRQ()函数的输入。在我发布的示例中,WKUPCT_ENABLE_IRQ()函数使得中断GPIO和两个按钮的极性。在您的情况下,您应该修改wkupct_enable_irq()作为:
wkupct_enable_irq(wkupct_pin_plect(gpio_button_port,gpio_button_pin)| wkupct_pin_select(gpio_sensor_port,gpio_sensor_pin),//选择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), // polarity low
1 / / 1 event
40); // debouncing time = 0
The GPIO_SENSOR_PORT and GPIO_SENSOR_PIN are for example. In your application you should make as input your GPIO sensor definitions. In order to advertise for 6 seconds when you wake up you should change the value of the advertising data time. Please go to the user_sleepmode.h file and change the value of APP_ADV_DATA_UPDATE_TO definition to 600. Also, I suggest you to check the polarity of your sensor in order to catch the interrupt and trigger the wakeup controller. For example, if the polarity of the sensor is low and you configure the polarity of wake up controller low, the interrupt will not be caught and the wake up controller will not be triggered. The example that I have provided in the previous post sets up a wake up signal from two sources, you can use that and replace the button with the interrupt using the polarity of your sensor.
3)当我在前一篇文章中已经提到了,当设备处于扩展睡眠模式时,您只能从BLE事件唤醒,当连接时,您将根据您与您安排的预定义连接间隔唤醒和睡眠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-semicondiondiondum/forums/post/dialog-smartbond-bl ...
谢谢pm_dialog.