This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541 Sleep Timer

Other Parts Discussed in Thread: CC2541

Currently I am attempting to use the Sleep Timer on the CC2541 in order to prevent my device from getting stuck in PM2 sleep for too long.

The way I am attempting to accomplish since the WDT does not run during PM2 is to use the Sleep Timer. From my understanding the Sleep Timers 32KHz is running at all times with the exception of PM3.

I have enabled the Sleep Timer Interrupt with the following code:

#pragma vector = ST_VECTOR
__interrupt void sleepTimerEvt_ISR(void)
{
  
  STIF = 0;
  
  //Reset Device  
  //HAL_SYSTEM_RESET();
}

void SimpleBLEPeripheral_Init( uint8 task_id )
{

  // Enable global interrupts
  EA = 1; 
 
  //Setup Sleep Timer Configurations
  //Disable Sleep Timer Capture Control Functionality
  STCC = 0x18;
  
  STIF = 0;
  STIE = 1;
  
  //Write Compare Value of Sleep Timer to be = 480K Clks = 15s @ 32kHz CLK
  //ST2 = 0x07;
  //ST1 = 0x53;
  //ST0 = 0x01;
  
  ST2 = 0x08;
  ST1 = 0x00;
  
  if (!STLOAD_LDRDY)
  {
     while(!STLOAD_LDRDY)
     {
        ST0 = 0x01;
     }
  }
  else
  {
    ST0 = 0x01;
  }
}

I get an interrupt as soon as the Sleep Timer Interrupt is enabled, also I am expecting this to take around 15s due to the configurations I have and due to it being based off of the 32KHz OSC. It constantly triggers an interrupt when running through debugger without even taking a second between triggers.

Am I missing something simple? Any suggestions would appreciated.

Thanks,

Peyton

  • If you intend to wake up from PM2 by timer, you can use osal_start_timerEX to start a scheduled event to do it.
  • So what would be the best way to do that? I'm not seeing exactly where it is going to sleep.

    I'm running into the problem that when a 3rd party device tries to connect to my peripheral device and send a password to it, it ends up locking up and never returning. In some cases it is getting stuck in sleep, and in others it seems like it is getting lost and the osal timers are getting out of sync. I was going to use the WDT but from what I understand it does not run in PM2, but even if it did it seems the max time would require me to wake up more often then I want to.

    Have you heard of this happening with the 3rd party devices trying to connect? Could there be underflow problems with the osal timers if it goes to sleep with only a few clocks left before the timer triggers?
  • After you define POWER_SAVING in SimpleBLEPheripheral, CC2541 would go to sleep mode when there is nothing to process in osal task queue. When I test SimpleBLEPeripheral with SimpleBLECentral, I don't see similar problem you described. Do you modify anything in SimpleBLEPheripheral and cause this issue?
  • thanks for the response,

    So the problem does not occur when I connect from BLE Central, that is not the problem. I also do not encounter the problem when connecting to the peripheral device using BLE Apps. Both of these methods work.

    I do however encounter a lock up when I try to connect to the ble peripheral device using the standard BLE menu on my Android phone and attempting to connect to it that way. My android phone prompts me for a password and once I enter it, the peripheral device is then locked up. It seemed all of my osal events were out of sync and were never being called again.

    So, in order to fix this problem I implemented a WDT, which fixed the problem for how the osal timers would never trigger when attempting to connect to the peripheral device in this way.

    When making a third party application, in which I request random services that do not exist from the peripheral, I was able to lock the peripheral device up in a different way altogether, this way caused it to get stuck in sleep mode, therefore the WDT did not work for this.

    That is why I went to the Sleep Timer, but now it seems the sleep timer is not working like I thought.

  • Additionally, I do understand "when" the device should go to sleep, I think what I meant to ask is "where" exactly in the code. For PM2 for example if I wanted to add an osal event that only allowed the device to sleep for 'x' amount of seconds. Where would I be putting this so that it would be started right before the device went to sleep.

    Do you not think it is possible that there is an underflow error in the ble stack? Suppose the ble stack is busy doing something such as processing an invalid connection request, and one of the osal timers events are missed. Would it not rollover to 0xFFFF? I'm not seeing in the code where this is accounter for.