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: CC2530 - Re-Start Pairing for SampleSwitch application with button (Z-Stack 1.2.2)

Part Number: CC2530
Other Parts Discussed in Thread: Z-STACK, ,

Hi

I would like to modify the SampleSwitch application contained in the Z-Stack 1.2.2 Folder in that way, that i can start pairing to a coordinator by pressing a button.

After the SampleSwitch has been paired successfully, it should be able to re-pair the SampleSwitch application again by pressing the same button.

What i don't know ist, which API-Function i have to call and which compiler flags i need so set to be able to achieve my goal.

Is it required to have EZ-Mode enabled?

SampleSwitch should act as an EndDevice which go to sleep for every 200ms.

By the way, is it a good idea to use Z-Stack 3.0 for CC2530 devices?

Thank you for your help.

Regards

Claudio

  • Hi Claudio,

    Please clarify your intent as what you've described is already accomplished for Z-Stack SampleSwitch examples with a SMARTRF05EB + CC2530EM.  You can review the Z-Stack Home Sample Application User's Guide for more information.  EZ-Mode is not required, however it is recommended.  End Devices are sleepy by default and you can control the POLL_RATE as desired.  I would recommend using Z-Stack 3.0.2 for new project development.

    Regards,
    Ryan

  • Thank you for your answer.

    Ok, when my desired behaviour is already implemented in the above mentioned examples, then this is excellent.
    I will try it and tell you if it was working as expected or not.

    One more question:

    I saw, that Zigbee1.2 End devices are able to join a zigbee 3.0 Network (as long as this supports legacy devices).

    But is a Zigbee3.0 EndDevice also be able to join a Zigbee1.2 network?

    Thanks

  • Yes, Zigbee3.0 EndDevice should also be able to join a Zigbee1.2 network.

  • Thank you for your answer.

    I want to build a firmware which behaves the following:

    After booting waiting for a button press.

    After button press, try to join an existing network. The network is created by an ti ZNP (zigbee2mqtt)
    The device should act as an end-device. The Device contains a relais and also a button to switch the relais.

    Now this "double function" is a bit confusing to me. When pressing the button, this should only toggle the relais, but the ZNP should get informed about the new state of the relais. The ZNP should also be able to toggle the relais like a lamp.

    Now im asking myself where to start. Should i use SampleLamp?
    Does this sample project inform the network about changes of the state?

    Thank you for your answer.

  • Based on the description of your solution I think you should start with SampleLight and have the on/off state of the lamp automatically report to the ZNP by creating a bind on the ZED with ZDP_BindReq.  Make sure that the on/off cluster attribute is set to reportable.

    Regards,
    Ryan

  • Hi Ryan

    Thank you very much for your answer. I wish i had the same overview about Z-Stack like you. Are there any document (beneath the usual Z-Stack docu) which you would reccomend me?

    And by the way, what do i need to strip out of the SampleLight application to get it automatically pairing / joining a network at startup?

    Since i dont have any official eval boards. Instead i am using a board with just an CC2530 on it with one button and one LED. I would like to get a minimal example which joins a network.

    These are my actual symbols:

    SECURE=1
    HAL_KEY=FALSE
    HAL_LED=FALSE
    HAL_LCD=FALSE
    HAL_UART=FALSE
    TC_LINKKEY_JOIN
    NV_INIT
    NV_RESTORE
    xHOLD_AUTO_START
    ZTOOL_P1
    MT_TASK
    MT_APP_FUNC
    MT_SYS_FUNC
    MT_ZDO_FUNC
    LCD_SUPPORTED=FALSE
    MULTICAST_ENABLED=FALSE
    ZCL_READ
    ZCL_WRITE
    ZCL_REPORT
    xZCL_EZMODE
    ZCL_BASIC
    ZCL_IDENTIFY
    ZCL_ON_OFF
    ZCL_SCENES
    ZCL_GROUPS
    xZCL_LEVEL_CTRL
    ZCL_DIAGNOSTIC
    FEATURE_SYSTEM_STATS

    Do i need EZMODE for my End-Device?

    Thank you for your help

    Regards

  • Dear Ryan

    Thank you very much for your answer.

    I will take a look into them and will update this topic as soon as possible :)

  • Dear Ryan

    I was able to fullfill my requirements. But i have some new questions.

    But before i start, here is, how i accomplished my requirements:

    I set all my GPIOs at the beginning of the init section:

      //DTB1905
      P0SEL &= ~((BV(5)|BV(6)|BV(7)));
      P1SEL &= ~(BV(0)|BV(2)|BV(3)|BV(4));
      P0DIR |= ((BV(5)|BV(6)|BV(7)));
      P1DIR |= (BV(0));
      P1INP = 0xFF; //1= no Pullup.
    
      P1DIR &= ~(BV(2)|BV(3)|BV(4)); //1= Output

    I dont bind my attributes to the coordinator. Instead i directly send a report to it:

    	  zclReportCmd_t *pReportCmd;
    
    	  pReportCmd = osal_mem_alloc( sizeof(zclReportCmd_t) + sizeof(zclReport_t) );
    	  if ( pReportCmd != NULL )
    	  {
    	    pReportCmd->numAttr = 1;
    	    pReportCmd->attrList[0].attrID = ATTRID_ON_OFF;
    	    pReportCmd->attrList[0].dataType = ZCL_DATATYPE_BOOLEAN;
    	    pReportCmd->attrList[0].attrData = (void *)(&RELAIS_STATE);
    
    	    zclSampleLight_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
    	    zclSampleLight_DstAddr.addr.shortAddr = 0;
    	    zclSampleLight_DstAddr.endPoint=1;
    
    	    zcl_SendReportCmd( SAMPLELIGHT_ENDPOINT, &zclSampleLight_DstAddr,
    	                       ZCL_CLUSTER_ID_GEN_ON_OFF,
    	                       pReportCmd, ZCL_FRAME_CLIENT_SERVER_DIR, TRUE, zclSampleLightSeqNum++ );
    	  }
    
    	  osal_mem_free( pReportCmd );

    I dont know if this approach brings any drawback with it.
    I have also started an event, which triggers every 300ms.

    osal_start_reload_timer( zclSampleLight_TaskID, MY_OWN_REPORTING_EVT, 300 );

    Inside of the event loop, i check for a button press:

      if ( events & MY_OWN_REPORTING_EVT )
       {
    	  sysCheckSwitchLoop(); //Do custom stuff
    
    	  if(!P1_3) //Reset Networkstate and start rejoining
    	  {
    		  zclSampleLight_BasicResetCB();
    	  }
    ...
    }

    This works quite well and as expected. But i was not able to figure out, how one should work with buttons / keys.
    Instead of polling my button every 300ms, i would like to react on an interrupt. But for me, the project structure of Z-Stack apllications are quite confusing.

    I thought, that all user-code reside in the source folder of the each project. But i saw, that also ZMain.c, and HAL/Target/CC2530EB and also Tools/f8wConfig.cfg can contain user-code.

    So this circumstance makes it quite complex to build a clean project.
    What is the best approach to get a clean project structure?

    In my opinion, it would be the best if all user-code will remain in one single directory and that all library code will reference, for example, to the components directory. But the actual structure looks quite confusing. Maybe i didnt got the point, how to work with this structure.

    This leads me to my last question.
    I would like to enable some power saving options. Actually, my board draws around 8mA @ 3.3V. Constantly. If i enable POWER_SAVING, the current consumption is still 8mA but the board does not respond to any button presses or any messages.

    Since i also send messages to my Application i would like to put the device into sleep for around 200-300ms and then poll for new messages, check my button state and enter sleep mode again. In a perfect world, the device would also exit sleep mode after a button press. But this is not very important.

    I hope you can help me to clarify some questions.

    Thank you for your help.

  • It looks like there’s current leakage on your board. I suggest you to check your IO settings and set unused pin to tri-state in your application init function to see if it can reduce the power consumption.

  • Hi Chen

    Thank you for your answer. And this on a sunday.

    After starting the debuging process and hitting the first breakpoint, the current consumption ist around 2.8mA. (This could be from some pullup resistors on the board itself). When starting the execution, the current draw increases upt to 8.7mA. If i now pause the execution, the consumption decreases down to 5.6mA.

    During normal execution, the consumption is continuously at 8.7mA. Therefore i think i could still be able to decrese this by setting some POWER_SAVING settings. But unfortunately, i was not able to reach some progress. 

    I have set all unused pins to input:

      P0SEL = 0x00;//&= ~((BV(5)|BV(6)|BV(7)));
      P1SEL = 0x00;//&= ~(BV(0)|BV(2)|BV(3)|BV(4));
      P2SEL = 0x00;
    
      P0DIR = 0x00;
      P1DIR = 0x00;
      P2DIR = 0x00;
    
      //P0DIR |= ((BV(5)|BV(6)|BV(7)));
      P1DIR |= (BV(0));
      P0INP = 0xFF; //1= no Pullup.
      P1INP = 0xFF; //1= no Pullup.
      P2INP = 0xFF; //1= no Pullup.

    But the current consumption has not changed. Still 8.59mA

    My Symbols:

    SECURE=1
    TC_LINKKEY_JOIN
    HAL_KEY=FALSE
    HAL_ADC=FALSE
    HAL_LED=FALSE
    NV_INIT
    NV_RESTORE
    xPOWER_SAVING
    NWK_AUTO_POLL
    xHOLD_AUTO_START
    ZTOOL_P1
    MT_TASK
    MT_APP_FUNC
    MT_SYS_FUNC
    MT_ZDO_FUNC
    xLCD_SUPPORTED=DEBUG
    MULTICAST_ENABLED=FALSE
    ZCL_READ
    ZCL_WRITE
    ZCL_REPORT
    ZCL_EZMODE
    ZCL_BASIC
    ZCL_IDENTIFY
    ZCL_ON_OFF
    xZCL_SCENES
    xZCL_GROUPS
    xZCL_LEVEL_CTRL
    xZCL_DIAGNOSTIC
    FEATURE_SYSTEM_STATS

    As mentioned earlied, if i enable POWER_SAVING, the code doenst get executed correctly anymore.

  • OK, i have solved the problem.

    I didnt installed a 32KHz Oscillator. Surprisingly, the CODE anyway went over MAC_RADIO_TIMER_WAKE_UP() sometimes.

    https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread/f/158/t/17360?Infinite-loop-at-MAC-RADIO-TIMER-WAKE-UP-function-how-to-solve-it-

    I had to insert:

    OSC32K_CRYSTAL_INSTALLED=FALSE into my compile flags.

    After that, my power consumption went down to 0.5mA.
    Well done!

    Now one last question, how could i wakeup after i pressed a button?

    Thanks

  • You can define ISR_KEYINTERRUPT in your project and it will enable key interrupt service in hal_key.c. I would suggest you to study hal_key.c to know more details about how to register a GPI as interrupt source and trigger ISR to handle it.