Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Compiler/CC2541: cc2541 sleep and wake up with button(p0.0 pin)

$
0
0

Part Number:CC2541

Tool/software: TI C/C++ Compiler

hi

I need your advice. about cc2540 keyfob button(p0.0 pin) action.

I am using cc2541mini DK (there is cc2541 keyfob, packet sniffer and ccDebuger)

I am using SimpleBLEPeripheral project (ble stack 1.4.0) with POWER_SAVING,.

I am trying to achieve this. 

1. power up : keyfob work nomaly( advert, periodic event, etc ) with POWER_SAVING
   2. button is long pressd(more than 3sec) : keyfob go sleep
   3. button is long pressd again :  keyfob wake up and work nomaly with POWER_SAVING

no problem in 1 and 2, I have a problem in no.3, it works intermittently.
Please advise what the problem is.


I changed HandleKey function and KEY Event in the project like this


static void keyfobapp_HandleKeys( uint8 shift, uint8 keys )
{
  if ( keys & HAL_KEY_SW_1 )
  {   
      osal_start_timerEx( simpleBLEPeripheral_TaskID, KEYHOLD_EVT, 0 ); 
  } 
}

bool sys_wake = TRUE;  //global variable, sleep/wake status
if ( events & KEYHOLD_EVT )
{
    if ( P0_0 == 0 ) //button is pressed
    { 
          sw1_hold_cnt++;
          osal_start_timerEx( simpleBLEPeripheral_TaskID, KEYHOLD_EVT, 1000); 
    }
    else  //button is released
    {  
          if ( sw1_hold_cnt >= 3 ) 
          { 

                if( sys_wake == TRUE )
                {

                         uint8 turnOnAdv = FALSE; 

                         GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &turnOnAdv );

                         osal_stop_timerEx(simpleBLEPeripheral_TaskID, PERIODIC_EVT);

                         sys_wake = FALSE;
          
                         //hal_sleep(0);
               }
               else
               {

                         uint8 turnOnAdv = TRUE;

                         GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &turnOnAdv );

                         osal_start_timerEx(simpleBLEPeripheral_TaskID, PERIODIC_EVT, 0);

                         sys_wake = TRUE;

               }  

               
       }
       sw1_hold_cnt = 0;
    }
    return ( events ^ KEYHOLD_EVT );
}


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>