领导不会留任when DA14583 enters sleep mode

Learn MoreFAQsTutorials

6 posts / 0 new
Last post
idarshan
Offline
Last seen:10 months 2 weeks ago
加入:2017-05-24 12:49
领导不会留任when DA14583 enters sleep mode

I am using ble_all_in_one example and modifying it for one of my functionality. I am configuring an LED GPIO in set_pad_function() and trying to make that GPIO high in button_press_callback. So use case is that to turn on LED when the button is pressed. Now LED turns on but it goes of in fraction of second. I am not turning of the LED in code, but seems like DA14583 goes to sleep and due to that LED turns off. How to make LED stay on even when DA14583 goes to sleep? Following is my modfied code from ble_all_in_one example code:

//In user_periph_setup.c
void set_pad_functions(void) // set gpio port function mode
{
//... other existing code
GPIO_ConfigurePin(GPIO_RED_LED_PORT, GPIO_RED_LED_PIN, OUTPUT, PID_GPIO, false);
GPIO_ConfigurePin(GPIO_GREEN_LED_PORT, GPIO_GREEN_LED_PIN, OUTPUT, PID_GPIO, false);
GPIO_ConfigurePin(GPIO_BLUE_LED_PORT, GPIO_BLUE_LED_PIN, OUTPUT, PID_GPIO, false);
}

// in user_all_in_one.c
static void app_button_press_cb(void)
{
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();
}

GPIO_SetActive( GPIO_GREEN_LED_PORT, GPIO_GREEN_LED_PIN); //Added by me
}

Please let me know what wrong I am doing here?

Appreciate your help.

Device:
PM_Dialog
Offline
Last seen:13 hours 14 min ago
Staff
加入:2018-02-08 11:03
Hi idarshan,

Hi idarshan,

Could you please try to describe a little bit more what you are trying to accomplish? If I understood correctly you would like to switch on the LED while the DA14580 starts advertising and upon the timer expiration that device should go to sleep mode and switch off the led? If I misunderstood something, please correct me. In case you mean that a possible solution will be the following:

  • In user_periph_setup.c : GPIO_ConfigurePin(GPIO_LED_PORT, GPIO_LED_PIN, OUTPUT, PID_GPIO, true);
  • Add GPIO_SetInactive(GPIO_LED_PORT , GPIO_LED_PIN); in the adv_data_update_timer_cb

Please try this one and let me know if you have any questions.

Thanks, PM_Dialog

idarshan
Offline
Last seen:10 months 2 weeks ago
加入:2017-05-24 12:49
I want to turn on the LED

I want to turn on the LED when I press the button first time and turn off the LED when I press the button again. Right now, after button press, LED turns on, but then it turns off automatically as DA14583 goes to sleep. I want to keep LED on even when DA14583 goes to sleep. I hope you understood the problem statement now. Please let me know if you want more elaboration.

PM_Dialog
Offline
Last seen:13 hours 14 min ago
Staff
加入:2018-02-08 11:03
Hi idarshan,

Hi idarshan,

The device retains the pin's state when it goes in sleep mode, so while you are in sleep mode the led should remain ON, but when waking up the device will run the periph_init() function and when that part of the code executes it will also reconfigure the pins in their default state. So in order to keep the LED on at all times you will have to "remember" the state of the pin when waking up, and when the periph_init() function executes you will have to re-apply the value of the pin while it was sleeping. Le t me tell you something for clarification. In the ble_app_all_in_one example of the SDK, the device starts advertising for a predefined amount of time which is 10 seconds (APP_ADV_DATA_UPDATE_TO). Upon the timer expiration, the device stops advertising and will enter the deep sleep mode. This means that all the peripherals are powered off and you can wake up inly from the wake-up controller. According to your description, you would like to turn ON/OF the led when the device is advertising? Be aware that the DA14583 will go to sleep mode between the advertising or connections intervals. The code snippet that you have posted into your initial post, will turn on the led when the device wake up from the permanent sleep mode.

Thanks, PM_Dialog

idarshan
Offline
Last seen:10 months 2 weeks ago
加入:2017-05-24 12:49
谢谢你的回复。I

谢谢你的回复。我认为你是misunderstanding my usecase. I do not want to turn LED on/off on advertising start/stop. My use case has nothing to do with advertising. I want to turn on the LED when button is pressed, keep the LED on until the button is pressed. When user releases the button, turn off the LED. I hope this clarifies my use case.

So your last response on this thread does not solve the problem for my usecase. Can you please give proper solution to this?

PM_Dialog
Offline
Last seen:13 hours 14 min ago
Staff
加入:2018-02-08 11:03
Hi idarshan,

Hi idarshan,

In the user_all_in_one.c file, you should do the following modifications:

  1. Add a global variable into the retention ram. This flag will notify the application if the led is on or off.

bool led_flag__attribute__((section("retention_mem_area0"),zero_init)); // @RETENTION MEMORY

  1. Add the following code snippet into app_button_press_cb()

led_flag= !led_flag ;

if(led_flag == true)

{

GPIO_SetActive(GPIO_LED_PORT , GPIO_LED_PIN);

}

else if(led_flag == false)

{

GPIO_SetInactive(GPIO_LED_PORT , GPIO_LED_PIN);

}

app_button_enable();

  1. In the user_app_adv_start() and user_app_init() call the app_button_enable() function in order to enable the button.

In the user_periph_setup.c file:

  1. extern bool led_flag ;
  2. In the set_pad_functions() modify the LED configuration as follow:

GPIO_ConfigurePin(GPIO_LED_PORT, GPIO_LED_PIN, OUTPUT, PID_GPIO, led_flag);

The device starts advertising and it goes into sleep between advertising intervals. So, every time that the device wakes up, the BLE_WAKEUP_LP_Handler will be executed and if you check this hander triggers the periph_init() function. So in order to keep the LED on at all times you will have to "remember" the state of the pin when waking up, and when the periph_init() function executes you will have to re-apply the value of the pin while it was sleeping.

Thanks, PM_Dialog