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: CC2541

Part Number: CC2541

Hi everyone!
I use CC2541 and as a basis I took SimpleBLEPeripheral example.
In the project I use Advertising, Observer, POWER_SAVING and periodic event.
After wake up from sleep mode, the advertising is dosn’t work anymore. But I added next loop to the function halSleep:
while(1)
{
    HAL_SLEEP_SET_POWER_MODE();
    if( IRSensorObstacleDetected() )
        break;
    /* if obstacle not detected, go to sleep again on 100 ms */
    sleepTimer = halSleepReadTimer();
    halSleepSetTimer( sleepTimer, HAL_SLEEP_MS_TO_32KHZ( 100) );
}


I understand that some of the tasks didn’t expect that sleep can be very long.
But which tasks I must to stop before go to sleep, or what I need to reinitialize after exit from sleep?


Thanks for the help!

  • Hi Vasyl,

    It's not entirely clear what you are doing, but you should not be calling sleep functions manually. Whenever no tasks are active, the sleep mechanism will put the device to sleep in any case.

    Let's say you are advertising, and you want to sleep for a while instead of advertising. What you do then is to disable advertising and set an osal timer to wake you up later so you can restart advertising.

    Technically, if no BLE activity is ongoing, you could call the sleep functions with no adverse effect, but if the stack is active, synchronization between the stack state, radio compare registers, the radio mac timer and the sleep timer will probably get out of sync and things will not work.

    Best regards,
    Aslak
  • Hi Aslak,

    Thanks for the prompt reply.
    I do not calling the sleep function manually, I just added the detection of an obstacle by an infrared sensor in function halSleep, and if there is no obstacle then continue sleep for another 100 ms. I do this to minimize consumption (without performing a complete wakeup mechanism). But now it's not important any more, I solved the problem the problem. I stopped Advertising, stopped Discovery and unsubscribed from the periodic timer. Next, in the halSleep function, I check if there is a a next timout for wakeup, if not, then only in this case I enabling the infrared detector.

    It looks like this,

    instead :
    // HAL_SLEEP_PM3 is entered only if the timeout is zero
    halPwrMgtMode = (timeout == 0) ? HAL_SLEEP_DEEP : HAL_SLEEP_TIMER;

    I added :
    if( timeout == 0 )
    {
    timeout = HAL_SLEEP_MS_TO_32KHZ( 100 );
    sleepDeep = 1;
    }
    halPwrMgtMode = HAL_SLEEP_TIMER;

    then I analyze variable sleepDeep

    while(1)
    {
    HAL_SLEEP_SET_POWER_MODE();
    If( !sleepDeep )
    break;
    if( IRSensorObstacleDetected() )
    break;
    /* if obstacle not detected, go to sleep again on 100 ms */
    sleepTimer = halSleepReadTimer();
    halSleepSetTimer( sleepTimer, HAL_SLEEP_MS_TO_32KHZ( 100) );
    }

    After a full wake up, I will resume the Advertising, Discovery and the periodic timer.

    Now the Advertising work fine! Thanks you!

    But the discovery does not work still.
    I continue to look for this problem.
  • Aslak, thanks you very much!
    Now I have no problems with sleep mode.