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.

CC2530: HAL_KEY_SW_6 wake up device and scan for hub

Part Number: CC2530

Hi,

I wanted to know how it would be possible to program the CC2530 so that when I press HAL_KEY_SW_6, it would start scanning for a hub if it is not currently connected to it? I am using the SampleLight program and already have it so that when I press HAL_KEY_SW_6, the CC2530 wakes up. However I just need it to scan for a hub if it isn't connected to one currently.

  • You can call ZDApp_StartJoiningCycle() when you want your device to start scanning network to join.
  • I only have this in the init, but not when HAL_KEY_SW_6 is pressed. How do I make it so that it will do ZDApp_StartJoiningCycle() when HAL_KEY_SW_6 is pressed and ONLY if the CC2530 is not currently connected to the hub?
  • You can call ZDApp_StartJoiningCycle anyway when SW6 is triggered. ZDApp_StartJoiningCycle will check if device is under DEV_INIT or DEV_NWK_DISC state to start joining process.
  • I added the code in the below, but however when I press SW6, it does not start scanning for a hub. I did not have the CC2530 connected to a hub previously.

    if ( keys & HAL_KEY_SW_6 )
    {
    ZDApp_StartJoiningCycle();

    osal_stop_timerEx( zclSampleLight_TaskID, TURNOFF_MOTOR_EVT);
    osal_start_timerEx( zclSampleLight_TaskID, TURNOFF_MOTOR_EVT, 5000);
    ret=osal_start_timerEx( zclSampleLight_TaskID, TURNOFF_MOTOR_EVT, 5000);
    KeyPressCnt=0;
    osal_start_timerEx( zclSampleLight_TaskID, KEYHOLD_EVT, 100);

    // toggle local light immediately
    zclSampleLight_OnOff = zclSampleLight_OnOff ? LIGHT_OFF : LIGHT_ON;
    }
  • Thanks for your help. I missed some code and added the rest as shown below. Now when I press SW6, it scans for the hub and then goes back to sleep after the set time from zgDefaultRejoinScan value.

    if ( keys & HAL_KEY_SW_6 )
    {
    ZDApp_ChangeState(DEV_NWK_DISC);
    // Restart scan for rejoin
    ZDApp_StartJoiningCycle();
    osal_stop_timerEx( ZDAppTaskID, ZDO_REJOIN_BACKOFF );
    osal_start_timerEx( ZDAppTaskID, ZDO_REJOIN_BACKOFF, zgDefaultRejoinScan );

    osal_stop_timerEx( zclSampleLight_TaskID, TURNOFF_MOTOR_EVT);
    osal_start_timerEx( zclSampleLight_TaskID, TURNOFF_MOTOR_EVT, 5000);
    ret=osal_start_timerEx( zclSampleLight_TaskID, TURNOFF_MOTOR_EVT, 5000);
    KeyPressCnt=0;
    osal_start_timerEx( zclSampleLight_TaskID, KEYHOLD_EVT, 100);

    // toggle local light immediately
    zclSampleLight_OnOff = zclSampleLight_OnOff ? LIGHT_OFF : LIGHT_ON;
    }
  • You are welcome and it's good to know it works now.
  • Just asking, if the CC2530 is connected to the hub and I press SW6, will the device still look for a hub or not?
  • If CC2530 is connected to the hub and you press SW6, CC2530 won't look for a hub.