Using RTC to Put BLE Device to Sleep for Hours

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Device PSoC4 CYBLE-224116-01

   

Hello,

   

I am trying to create an application where the user can put the BLE device to sleep for certain hours.

   

I have created a service which has two characteristics; 1. Sleep time and 2. SleepNowFlag.

   

The user enters the duration for which it wants the BLE device to sleep, and they write on to the SleepNowFlag when they want to put the BLE  to sleep.

   

The firmware in the BLE device keeps checking the flag; and when the flag is set it puts itself to sleep.

   

Now i want the device to wakeup when the sleep time is over and start advertising. I thought of using the RTC Alarm Feature but am not able to figure out how.

   

Please Help!

0 Likes
1 Solution
Anonymous
Not applicable

The WDT is able to run while the chip is in deep-sleep; That might be your best option, as I'm not sure the RTC will run while in deep-sleep mode.

View solution in original post

0 Likes
14 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Please post your code so we can check it.

0 Likes
Anonymous
Not applicable

The WDT is able to run while the chip is in deep-sleep; That might be your best option, as I'm not sure the RTC will run while in deep-sleep mode.

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a display of what works in sleep modes.

   

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Check this document for information. http://www.cypress.com/file/104566/download

0 Likes
Anonymous
Not applicable

Thanks @bobgoar; Linking the documentation is helpful

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello Guys,

   

Thank you for your inputs. What i have done is instead of putting BLE to sleep, i have called the CyBle_Stop() to completely stop the Stack(Also i didn't want the BLE to wake up at connection intervals). I am using the RTC Alarm feature to wake up the BLE and restart the stack using CyBle_Start(). Kindly correct me or suggest me alternatives on how to go about this.
I want the ble to completely shut itself down for a user defined period(minutes or hours).

0 Likes
Anonymous
Not applicable

Based on previous interactions with the cypress employees, they mentioned that as long as the BLE radio is not advertising, scanning, or connected, then it should be inactive (no power consumption) when you put it into sleep mode. Then you just skip calling th cyble_processevents() and there will be no wakeups from the BLE chip arbitrarily. I ran into issues when I tried doing the method you are mentioning above; starting/stopping the cyble stack during runtime. Iirc, I ran into memory or stack errors when trying to run operations, and changing the chip to either reset and cyble_start() from the reset or just going to sleep with no activity ended up cleaning up the bugs/errors.

   

Edit: If you make sure the BLE is not connected, scanning, or advertising and then put the BLE stack to sleep, then just wakeup the BLE module when you want to use it. It should be the same effect as what you are attempting above. Also, it will reduce processing time spent initializing/clearing the BLE stack. 

0 Likes
Anonymous
Not applicable

You mean to say; if after putting the device to sleep, i stop calling CyBle_ProcessEvents() then the device won't wake up at intervals?

   

and is there a function to wakeup the BLE from sleep/deep-sleep, because all the functions i read were to wake up individual components...

0 Likes
Anonymous
Not applicable

If you put the BLE chip to sleep with no active advertisement, connection, or scanning commands (cyble_state is disconnected/idle), then when you put the chip to sleep, it won't wake up from a BLE interrupt.

   

CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP); //Tries to put the BLE chip into deep-sleep
        blessState = CyBle_GetBleSsState(); //Returns the current BLE state (whether it went into sleep, deep sleep, or is still active
        if((blessState == CYBLE_BLESS_STATE_ECO_ON ||    //Not sure what exactly this event is, but the ECO is the External Crystal Oscillator, and the cypress example code had it as a valid deep-sleep state.
        blessState == CYBLE_BLESS_STATE_DEEPSLEEP)) { //If BLE chip entered deep sleep mode
            CySysPmDeepSleep();    /Put processor into deep sleep power mode

   

            cyble_exitlpm() //Processor won't execute this instruction until an interrupt wakes up the chip; If you turned off all of the BLE activity before deep sleep, then the BLE chip won't wakeup the processor, only other peripherals you have defined to do so. This instruction wakes up the BLE chip in order for you to call BLE APIs

   

}

0 Likes
Anonymous
Not applicable

Thanks e.pratt;

   

I will try this out. But is it possible for the server(peripheral/slave) to initiate disconnection(I guess not; but if you have a workaround)?I don't see an api which is similar to CyBle_GapcConnectDevice() to initiate disconnection.

0 Likes
Anonymous
Not applicable

You can use the CyBle_GapDisconnect(handle) function to initiate disconnection from either side. The latest BLE stack component also includes the CyBle_GapDisconnectWithReason(handle, reasonfunction if you want a specific reason code, though this is most often not necessary.

   

Jeff

0 Likes
Anonymous
Not applicable

Thanks Jeff!! I will try it out.

   

Maxwin

0 Likes
Anonymous
Not applicable

Hey Jeff,

   

Could you please tell what this event means?

   

*  <tr>
*    <td>CYBLE_BLESS_STATE_ECO_ON</td>
*    <td>BLE Sub System is in process of wakeup from Deep Sleep Mode and ECO(XTAL) is turned on.
*        CPU can be put in Deep Sleep Mode.</td>
*  </tr>

0 Likes
Anonymous
Not applicable

Hi Maxwin,

   

That's not technically an event; it's a value returned from a query concerning the current operating state of the BLE stack, specifically concerning when it is or is not safe to enter various sleep modes. The best explanation available for this is in Section 2.3 of AN92584, which you can find here:

   

http://www.cypress.com/documentation/application-notes/an92584-designing-low-power-and-estimating-ba...

   

It's a very short-lived state where the ECO is stabilizing.

   

Jeff

0 Likes