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.

Zstack with external antena X2401c

Other Parts Discussed in Thread: CC2591, CC2592, Z-STACK, CC2590, CC2530, CC2531

Hi all,

i want design fw to transmit RF signed with IC RFaxis X2401c,

My problem:

IC X2401c must control transimit and receive RF with 2 pin: Tx enable and Rx enable.

I use Zstack Home automation 1.2.1

I should define Tx enable and Tx enable where in Zstack without affecting Zstack

I appreciate any help now, thanks you!

  • Z-Stack works with CC2590, CC2591, CC2592, and SE2431L as range extender but no X2401C. If you insist using X2401C, i suppose you have to do it by yourslef.
  • Yes, i want use X2401C. how are you guide me use X2401C with Zstack ?
    Sorry because my english very bad :)
  • For HW part, You can refer to www.ti.com/.../swra308a.pdf. For Z-Stack implementation, you can refer to the define HAL_PA_LNA.
  • Yes, i think i found my answer.
    I will retry and feedback in this weekend
    Thanks you very much Yikai Chen
  • You are welcome.
  • Hi Yikai Chen,
    In my project, i use Home automation. I fix the following:
    In file hai_board_cfg.h, i fix #define HAL_PA_LNA // define antenna 2591 and function HAI_BOARD_INIT() i fix P2DIR |= BV(0); // pin HGM <->RXEN x2401c
    In file mac_radio_defs.h :
    /* For Skyworks parts only CPS maps closely to the HGM line */
    #define HAL_PA_LNA_RX_HGM() st( P2_0 = 1; )
    #define HAL_PA_LNA_RX_LGM() st( P2_0 = 0; )

    Can you more specific guidance for me change CC2591 to X2401c???
    Thanks you!!

  • At least, I think you still need to revise the following registers in macRadioTurnOnPower().

    /* P1_1 -> PAEN */
    RFC_OBS_CTRL0 = RFC_OBS_CTRL_PA_PD_INV;
    OBSSEL1 = OBSSEL_OBS_CTRL0;

    /* P1_4 -> EN (LNA control) */
    RFC_OBS_CTRL1 = RFC_OBS_CTRL_LNAMIX_PD_INV;
    OBSSEL4 = OBSSEL_OBS_CTRL1;
  • Hi YiKai Chen kun,

    I success with antenna X2401c under your guide
    Thanks you very much!
  • Cool! It is good to know you make it work.

  • Hi YiKai Chen,
    Sorry because post this topic continuos...
    I have a problem with function AF_DataRequest()
    I have short address of ZEDs in my Zigbee network, i want send data with this address from ZC but i feel confused with that
    Can you guidance me as: How use, where use and How receive this data send??
    Thanks you,
  • You can download Z-Stack Mesh 1.0.0 and there is an GenericApp which show you how to use AF_DataRequest to send "Hello World" message on one side and receive it in another side.
  • ok, i will try
    i have other question:
    i have 1 ZC(Sample light) and 3 ZED(sample switch)
    While ZED use SW1 to on/off led in ZC. How to i know address ZED on/off.
    i have list address of 3 ZED but i don't know ZED on/off
    Thanks you
  • Don't understand your question. Your 3 ZEDs are all sample switch. There is no ON/OFF status on SampleSW. It only send ON/OFF/Toggle command.
  • Yes, 3 ZED send Toggle command to on/off LED in ZC
    Problem is: How is ZC know ZED send on/off to it?
    Exactly: i need short address of ZED has send toggle command
    Thanks you
  • If you need this information, you might have to get it from case ZCL_CLUSTER_ID_GEN_ON_OFF in zclGeneral_HdlInSpecificCommands(). There is a zclIncoming_t *pInMsg which contains source address.
  • Hi YiKai Chen,

    I apply sample Generic in SampleLight in project of me

    Function AF_DataRequest was run in ZC but in ZED i don't receive event AF_INCOMING_MSG_CMD

    Function Testled() of me blink led 2 to i know send data successfully.

    Can you help me receive data "hello world"  in ZED? I attach samplelight of ZC below

    Thanks you

    zcl_samplelight.czcl_samplelight.h

  • Try to revise zcl_event_loop() using the following red codes. You have to add AF_INCOMING_MSG_CMD case in your application event handler.

    uint16 zcl_event_loop( uint8 task_id, uint16 events )
    {
    uint8 *msgPtr;

    (void)task_id; // Intentionally unreferenced parameter

    if ( events & SYS_EVENT_MSG )
    {
    msgPtr = osal_msg_receive( zcl_TaskID );
    while ( msgPtr != NULL )
    {
    uint8 dealloc = TRUE;

    if ( *msgPtr == AF_INCOMING_MSG_CMD )
    {
    if ( ZSuccess!=zcl_ProcessMessageMSG( (afIncomingMSGPacket_t *)msgPtr ) )
    {
    // send it to another task to process.
    osal_msg_send( zcl_RegisteredMsgTaskID, msgPtr );
    dealloc = FALSE;
    }
    }
    else if ( zcl_RegisteredMsgTaskID != TASK_NO_TASK )
    {
    // send it to another task to process.
    osal_msg_send( zcl_RegisteredMsgTaskID, msgPtr );
    dealloc = FALSE;
    }

    // Release the memory
    if ( dealloc )
    {
    osal_msg_deallocate( msgPtr );
    }

    // Next
    msgPtr = osal_msg_receive( zcl_TaskID );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
    }

    // Discard unknown events
    return 0;
    }
  • Hi YiKai chen,
    where red codes???
    and zcl_event_loop() has enough as codes above.
    if data send with AF_DataRequest function,where buffer data receive?
  • Sorry, the followings should be in red

            if ( ZSuccess!=zcl_ProcessMessageMSG( (afIncomingMSGPacket_t *)msgPtr ) )
            {
              // send it to another task to process.
              osal_msg_send( zcl_RegisteredMsgTaskID, msgPtr );
              dealloc = FALSE;
            }

  • Hi YiKai Chen,
    I have a trouble problem
    1.) I have short address 16bit of ZED but its negative : "-11811"
    I taken addr of ZED by:
    In Sample_Init() I register:
    ZDO_RegisterForZDOMsg(task_id, Device_annce);
    In Sample_ProcessZDOMsgs case Device_annce i use:
    ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp(pMsg);
    AddrArray = pRsp->nwkAddr;//This short Address

    Why is this happen?
    2.) with AF_DataRequest:
    I define on ZED : - endpoint = 8
    - clusterID = 1
    And i use function as example Generic to send data on ZC:
    unsigned char theMessageData[] = "Hello world";//Data sent
    afAddrType_t dstAddr;
    dstAddr.addrMode = Addr16Bit;
    dstAddr.addr.shortAddr = AddrArray[0];
    SampleLight_epDesc.endPoint = SAMPLELIGHT_ENDPOINT; //8
    if ( AF_DataRequest( &dstAddr, &SampleLight_epDesc,
    SAMPLELIGHT_CLUSTERID,
    (byte)osal_strlen( theMessageData ) + 1,
    (byte *)&theMessageData,
    &SampleLight_TransID,
    AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
    Why on ZED don't event AF_INCOMING_MSG_CMD
    please help i can receive data , thanks you YiKai Chen very much again
  • 1. Short address is in hex format. Please don't interpret it to integer.
    2. I don't understand your question well.
  • Hi YiKai Chen.
    1, I maken short address of ZED as follows:
    "If you need this information, you might have to get it from case ZCL_CLUSTER_ID_GEN_ON_OFF in zclGeneral_HdlInSpecificCommands(). There is a zclIncoming_t *pInMsg which contains source address."
    2, I maken short address of ZED as follows:
    ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp(pMsg);
    ShortAddr = pRsp->nwkAddr;//This short Address

    They are diffirent, can you said why that? thanks you
  • Are you sure the two message comes from the same device? I am confused by what you intend to do?
  • Yes, I use only 1 ZED and 1 ZC. I want send data by function AF_DataRequest with short address 16bit but not complete
    Can you help me maken short address of ZED exactly???
  • You can register for device announcement event by ZDO_RegisterForZDOMsg(task_id, Device_annce); and add "if(pMsg->clusterID == Device_annce) {ZDO_DeviceAnnce_t devAnnce; ZDO_ParseDeviceAnnce(inMsg, &devAnnce);}" in your zclXXX_ProcessZDOMsgs. There is short address in devAnnce.nwkAddr.
  • Hi YiKai Chen,

    I have solved the problem send data, thank you very much.

  • It is good to know you solve the problem. If it is possible, please show us how you solve it to benefit others who have similar issue.
  • Yes.
    I use 1 ZC as SampleLight and 3 ZED as SampleSw. My initial trouble with the short address and endpoint to send data. MY Packet Sniffer don't use because i have only SMARTRF04EB.
    I use functionc NLME_GetShortAddr() to get short address by its. Later, i send short address, Endpoint, IEEE address of ZEDs to Coordinator with short address 0x0000 when its join on network. Coordinator save and use send data success.
    I hope receive feedback from you to perfect fw.
    Thanks you!
    my Function Packing information:
    char addrlong2[8]
    for(i=0;i<sizeof(addrlong);i++)
    addrlong[i] = 0;
    addrlong = NLME_GetExtAddr();
    addrshort = NLME_GetShortAddr();
    for(int i = 0;i<osal_strlen(SendBuffer);i++)
    SendBuffer[i] = 0;
    for(i=0;i<8;i++)
    {
    if(addrlong[7-i]<10)
    sprintf(addrlong2+i*2,"0%x",addrlong[7-i]);
    else
    sprintf(addrlong2+i*2,"%x",addrlong[7-i]);
    }
    sprintf(SendBuffer,"|ShortAddr: %d|IEEEAddr: %s|Endpoint: %d|\r\n",addrshort,addrlong2,SAMPLESW_ENDPOINT);
  • From Zigbee spec perspective, I would suggest you to register Device_annce and keep short/IEEE address in Device_annce event.
  • OK, i will try again.
    during the process of the project, if have questions, i will post this topic. i hope your hope
    best and regard
  • No problem.
  • Hi YiKai Chen,
    i try make short address of ZED from function ZDP_NwkAddrReq as follows:
    Init function i register : ZDO_RegisterForZDOMsg(zclSampleLight_TaskID, NWK_addr_rsp);
    In Hankey_event:
    if ( keys & HAL_KEY_SW_8 )
    {
    uint8 Addr64bit[8] = {0x00,0x12,0x4B,0x00,0x02,0xEF,0xDE,0x26};
    ZDP_NwkAddrReq(Addr64bit,ZDP_ADDR_REQTYPE_SINGLE,0,0);
    }

    In zclSampleLight_ProcessZDOMsgs:
    case NWK_addr_rsp:
    {
    uint16 a;
    ZDO_NwkIEEEAddrResp_t* pRspnew;
    pRspnew = ZDO_ParseAddrRsp(pMsg);
    a = pRspnew->nwkAddr;

    ////Printf a in here to uart but haven't
    }
    I set break point in case ZDO_CB_MSG: of event loop but haven't interrupt happen while i press button.
    Can you help me have short address from IEEE address?
  • Try to reverse the byte order in Addr64bit.
  • Hi YiKai Chen,
    1, I have changed but don't callback function zclSampleLight_ProcessZDOMsgs case NWK_addr_rsp:
    2, I use function send data AF_DataRequest from ZED to ZC success but from ZC to ZED don't success. Although i check carefully with short addr, IEEE addr, endpoint (8). Please give me advice about receive data in ZED from ZC?

    Thanks you,
  • I Bind ZC and ZED with EZ MODE. may be wrong here???
    EZMODE to affect bind ?
  • 1. Are you sure the device with this MAC address joins coordinator?
    2. I suggest you use Packet Sniffer to check this.
  • Hi YIKaiChen,

    1, I sure because i read it with SMARTRF04EB as image  attach

    2. I have only SmartRF04EB don't use Packet Sniffer. Can u tell me Condition of ZED to receive data ? i think sent success

    Best!

  • 1. I mean does this device joins to your coordinator's Zigbee network?
    2. ZED does polling to its parent node. If there is a data for ZED, the data would be kept on its parent node and wait for ZED to polling for it.
  • Hi YiKai Chen,

    1. I use smartrf04eb to read IEEE address on ZED(Sample SW) and On ZED i use NLME_GetShortAddr() printf  through UART

    So, it's ZED i need know Short address.

    2. My network haven't route. 1 ZC, 1 ZED.

    On ProcessZDOMsgs function, i has success with case Device_annce(when ZED join), case Match_Desc_rsp. but case NWK_addr_rsp not occur.

    I attach source hope you help me maken short address from ieee address

    /******************************************************************************
      Filename:       Project.c
      Revised:        $Date: 23/04/2015
      Revision:       
    
      Description:    Project redefine and designed by tuanna78
    
    
      Copyright 2004-2014 Texas Instruments Incorporated. All rights reserved.
    
      IMPORTANT: Your use of this Software is limited to those specific rights
      granted under the terms of a software license agreement between the user
      who downloaded the software, his/her employer (which must be your employer)
      and Texas Instruments Incorporated (the "License"). You may not use this
      Software unless you agree to abide by the terms of the License. The License
      limits your use, and you acknowledge, that the Software may not be modified,
      copied or distributed unless embedded on a Texas Instruments microcontroller
      or used solely and exclusively in conjunction with a Texas Instruments radio
      frequency transceiver, which is integrated into your product. Other than for
      the foregoing purpose, you may not use, reproduce, copy, prepare derivative
      works of, modify, distribute, perform, display or sell this Software and/or
      its documentation for any purpose.
    
      YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
      PROVIDED �AS IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
      INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
      NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
      TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
      NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
      LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
      INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
      OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
      OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
      (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
    
      Should you have any questions regarding your right to use this Software,
      contact Texas Instruments Incorporated at www.TI.com.
    ******************************************************************************/
    
    /*********************************************************************
     * INCLUDES
     */
    #include "ZComDef.h"
    #include "OSAL.h"
    #include "AF.h"
    #include "ZDApp.h"
    #include "ZDObject.h"
    #include "ZDProfile.h"
    
    #include "zcl.h"
    #include "zcl_general.h"
    #include "zcl_ha.h"
    #include "zcl_ezmode.h"
    #include "zcl_diagnostic.h"
    
    #include "zcl_samplesw.h"
    
    #include "onboard.h"
    
    /* HAL */
    #include "hal_lcd.h"
    #include "hal_led.h"
    #include "hal_key.h"
    #include "hal_uart.h"
    
    #if (defined HAL_BOARD_ZLIGHT) || (defined HAL_PWM)
    #include "math.h"
    #include "hal_timer.h"
    #endif
    #include "NLMEDE.h"
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    
    
    
    /*********************************************************************
     * TYPEDEFS
     */
    
    /*********************************************************************
     * GLOBAL VARIABLES
     */
    // This list should be filled with Application specific Cluster IDs.
    const cId_t Project_ClusterList[PROJECT_MAX_CLUSTERS] =
    {
      PROJECT_CLUSTERID
    };
    
    const SimpleDescriptionFormat_t Project_SimpleDesc =
    {
      PROJECT_ENDPOINT,              //  int Endpoint;
      PROJECT_PROFID,                //  uint16 AppProfId[2];
      PROJECT_DEVICEID,              //  uint16 AppDeviceId[2];
      PROJECT_DEVICE_VERSION,        //  int   AppDevVer:4;
      PROJECT_FLAGS,                 //  int   AppFlags:4;
      PROJECT_MAX_CLUSTERS,          //  byte  AppNumInClusters;
      (cId_t *)Project_ClusterList,  //  byte *pAppInClusterList;
      PROJECT_MAX_CLUSTERS,          //  byte  AppNumInClusters;
      (cId_t *)Project_ClusterList   //  byte *pAppInClusterList;
    };
    
    // This is the Endpoint/Interface description.  It is defined here, but
    // filled-in in Project_Init().  Another way to go would be to fill
    // in the structure here and make it a "const" (in code space).  The
    // way it's defined in this sample app it is define in RAM.
    endPointDesc_t Project_epDesc;
    
    /*********************************************************************
     * EXTERNAL VARIABLES
     */
    
    /*********************************************************************
     * EXTERNAL FUNCTIONS
     */
    
    /*********************************************************************
     * LOCAL VARIABLES
     */
    byte Project_TaskID;   // Task ID for internal task/event processing
                              // This variable will be received when
                              // Project_Init() is called.
    
    devStates_t Project_NwkState;
    
    byte Project_TransID;  // This is the unique message ID (counter)
    
    afAddrType_t Project_DstAddr;
    
    // Number of recieved messages
    static uint16 rxMsgCount;
    
    // Time interval between sending messages
    
    /*********************************************************************
     * LOCAL FUNCTIONS
     */
    static void Project_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
    static void Project_HandleKeys( byte shift, byte keys );
    static void Project_MessageMSGCB( afIncomingMSGPacket_t *pckt );
    static void Project_SendTheMessage( void );
    //define uart
    #define DEBUGUA 1
    #define RX_BUF_LEN 128
    #ifdef HAL_UART_DMA
    static void UARTInit(void);
    static void cbackUART(uint8 port, uint8 event);
    //static void DetectCmdFromUart(uint8 *StrCmd, uint8 len);
    static void HalUARTWriteHex(int port, int variable);
    #endif
    
    
    
    /*********************************************************************
     * @fn          Write hex, debug addr
     *
     * @brief       Modify from HalUARTWrite
     *
     * @param       none
     *
     * @return      none
     */
    static void HalUARTWriteHex(int port, int variable)
     {
        char str[8];
        for(int i = 0;i<sizeof(str);i++)
          str[i] = 0;
        sprintf(str,"%x\r\n",variable);
        HalUARTWrite(port,(uint8*)str,osal_strlen(str));
     }
    /*********************************************************************
     * @fn          cb UA
     *
     * @brief       cb ua
     *
     * @param       none
     *
     * @return      none
     */
    static void cbackUART(uint8 port, uint8 event)
    {
      uint8 pBuf[RX_BUF_LEN];
      uint16 len;
      
      if(event == HAL_UART_RX_TIMEOUT)
        {
          //Read UART
          len = HalUARTRead(HAL_UART_PORT_0,pBuf,RX_BUF_LEN);
          //DetectCmdFromUart(pBuf,len);
          //Trans
        }
    }
    /*********************************************************************
     * @fn          UARTInit
     *
     * @brief       Initialization function for the UART, as init system complete
     *
     * @param       none
     *
     * @return      none
     */
     void UARTInit(void)
    {
      halUARTCfg_t uartConfig;
      
      //Define config
      uartConfig.configured           = true;
      uartConfig.baudRate             = HAL_UART_BR_115200; //Baudrate
      uartConfig.flowControl          = FALSE;//delete flowcontrol
      uartConfig.flowControlThreshold = 64;
      uartConfig.rx.maxBufSize        = 128;
      uartConfig.tx.maxBufSize        = 128;
      uartConfig.idleTimeout          = 6;//Time out 6ms/ 1 char
      uartConfig.callBackFunc         = cbackUART; //time cback
      uartConfig.intEnable            = FALSE;//Delete interrupt
      
      HalUARTInit();
      HalUARTOpen(HAL_UART_PORT_0, &uartConfig);//Open Port 0 
    #if DEBUGUA
      HalUARTWrite(HAL_UART_PORT_0,"Designed firmware: tuanna78\r\n",28);
      HalUARTWrite(HAL_UART_PORT_0,"Vertion Zstack   : Z-Stack Home 1.2.1\r\n",39);
      HalUARTWrite(HAL_UART_PORT_0,"Begin            : 1/4/2015\r\n",29);
      HalUARTWrite(HAL_UART_PORT_0,"Complete         :         \r\n",29);
    #endif
    }
    
    /*********************************************************************
     * @fn      Project_Init
     *
     * @brief   Initialization function for the Generic App Task.
     *          This is called during initialization and should contain
     *          any application specific initialization (ie. hardware
     *          initialization/setup, table initialization, power up
     *          notificaiton ... ).
     *
     * @param   task_id - the ID assigned by OSAL.  This ID should be
     *                    used to send messages and set timers.
     *
     * @return  none
     */
    void Project_Init( uint8 task_id )
    {
      Project_TaskID = task_id;
      Project_NwkState = DEV_INIT;
      Project_TransID = 0;
    
      // Device hardware initialization can be added here or in main() (Zmain.c).
      // If the hardware is application specific - add it here.
      // If the hardware is other parts of the device add it in main().
    
      Project_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
      Project_DstAddr.endPoint = 0;
      Project_DstAddr.addr.shortAddr = 0;
    
      // Fill out the endpoint description.
      Project_epDesc.endPoint = PROJECT_ENDPOINT;
      Project_epDesc.task_id = &Project_TaskID;
      Project_epDesc.simpleDesc
                = (SimpleDescriptionFormat_t *)&Project_SimpleDesc;
      Project_epDesc.latencyReq = noLatencyReqs;
    
      // Register the endpoint description with the AF
      afRegister( &Project_epDesc );
    
      // Register for all key events - This app will handle all key events
      RegisterForKeys( Project_TaskID );
    
      // This app is part of the Home Automation Profile
      //zclHA_Init( &Project_SimpleDesc );
    
      // Register the ZCL General Cluster Library callback functions
     // zclGeneral_RegisterCmdCallbacks( PROJECT_ENDPOINT, &Project_CmdCallbacks );
      
      //Register callback function
      ZDO_RegisterForZDOMsg( Project_TaskID, End_Device_Bind_rsp );
      ZDO_RegisterForZDOMsg( Project_TaskID, Match_Desc_rsp );
      ZDO_RegisterForZDOMsg( Project_TaskID, IEEE_addr_rsp);
      ZDO_RegisterForZDOMsg( Project_TaskID, NWK_addr_rsp);
      ZDO_RegisterForZDOMsg( Project_TaskID, Device_annce);
      
    #ifdef HAL_UART_DMA
      UARTInit();
    #endif
    }
    
    /*********************************************************************
     * @fn      Project_ProcessEvent
     *
     * @brief   Generic Application Task event processor.  This function
     *          is called to process all events for the task.  Events
     *          include timers, messages and any other user defined events.
     *
     * @param   task_id  - The OSAL assigned task ID.
     * @param   events - events to process.  This is a bit map and can
     *                   contain more than one event.
     *
     * @return  none
     */
    uint16 Project_ProcessEvent( uint8 task_id, uint16 events )
    {
      afIncomingMSGPacket_t *MSGpkt;
    
      (void)task_id;  // Intentionally unreferenced parameter
    
      if ( events & SYS_EVENT_MSG )
      {
        MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( Project_TaskID );
        while ( MSGpkt )
        {
          switch ( MSGpkt->hdr.event )
          {
            case ZDO_CB_MSG:
              Project_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
              break;
    
            case KEY_CHANGE:
              Project_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
              break;
    
            case AF_INCOMING_MSG_CMD:
              Project_MessageMSGCB( MSGpkt );
              break;
    
            case ZDO_STATE_CHANGE:
              Project_NwkState = (devStates_t)(MSGpkt->hdr.status);
              if ( (Project_NwkState == DEV_ZB_COORD) ||
                   (Project_NwkState == DEV_ROUTER) ||
                   (Project_NwkState == DEV_END_DEVICE) )
              {
                // Start sending "the" message in a regular interval.
    
              }
              break;
    
            default:
              break;
          }
    
          // Release the memory
          osal_msg_deallocate( (uint8 *)MSGpkt );
    
          // Next
          MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( Project_TaskID );
        }
    
        // return unprocessed events
        return (events ^ SYS_EVENT_MSG);
      }
      return 0;
    }
    
    /*********************************************************************
     * Event Generation Functions
     */
    
    /*********************************************************************
     * @fn      Project_ProcessZDOMsgs()
     *
     * @brief   Process response messages
     *
     * @param   none
     *
     * @return  none
     */
    static void Project_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
    {
      switch ( inMsg->clusterID )
      {
      case IEEE_addr_rsp:
        {
          ZDO_NwkIEEEAddrResp_t* pRspnew2;
          pRspnew2 = ZDO_ParseAddrRsp(inMsg);
          
        }
      case NWK_addr_rsp:
      {
        ZDO_NwkIEEEAddrResp_t* pRspnew;
        pRspnew = ZDO_ParseAddrRsp(inMsg);
        HalUARTWriteHex(0x00, pRspnew->nwkAddr);
        break;
      }
        case End_Device_Bind_rsp:
          if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
          {
            // Light LED
            HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
          }
    #if defined( BLINK_LEDS )
          else
          {
            // Flash LED to show failure
            HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
          }
    #endif
          break;
    
        case Match_Desc_rsp:
          {
            ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
            if ( pRsp )
            {
              if ( pRsp->status == ZSuccess && pRsp->cnt )
              {
                Project_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
                Project_DstAddr.addr.shortAddr = pRsp->nwkAddr;
                // Take the first endpoint, Can be changed to search through endpoints
                Project_DstAddr.endPoint = pRsp->epList[0];
    
                // Light LED
                HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
              }
              osal_mem_free( pRsp );
            }
          }
          break;
          //Da lay dia chi khi thiet bi join mang dau tien thanh cong
      case Device_annce:
        {
        ZDO_DeviceAnnce_t devAnnce;
        ZDO_ParseDeviceAnnce(inMsg, &devAnnce);
        HalUARTWriteHex(0x00, devAnnce.nwkAddr);
        break;
        }
      }
    }
    
    /*********************************************************************
     * @fn      Project_HandleKeys
     *
     * @brief   Handles all key events for this device.
     *
     * @param   shift - true if in shift/alt.
     * @param   keys - bit field for key events. Valid entries:
     *                 HAL_KEY_SW_4
     *                 HAL_KEY_SW_3
     *                 HAL_KEY_SW_2
     *                 HAL_KEY_SW_1
     *
     * @return  none
     */
    static void Project_HandleKeys( uint8 shift, uint8 keys )
    {
      zAddrType_t dstAddr;
        if ( keys & HAL_KEY_SW_1 )
        {
          
        }
    
        if ( keys & HAL_KEY_SW_2 )
        {
          
        }
    
        if ( keys & HAL_KEY_SW_3 )
        {
          
        }
    
        if ( keys & HAL_KEY_SW_4 )
        {
          HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
          // Initiate a Match Description Request (Service Discovery)
          dstAddr.addrMode = AddrBroadcast;
          dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
          ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR,
                            PROJECT_PROFID,
                            PROJECT_MAX_CLUSTERS, (cId_t *)Project_ClusterList,
                            PROJECT_MAX_CLUSTERS, (cId_t *)Project_ClusterList,
                            FALSE );
        }
        if ( keys & HAL_KEY_SW_7 )
          {
            HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
    
          // Initiate an End Device Bind Request for the mandatory endpoint
          dstAddr.addrMode = Addr16Bit;
          dstAddr.addr.shortAddr = 0x0000; // Coordinator
          ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(),
                                Project_epDesc.endPoint,
                                PROJECT_PROFID,
                                PROJECT_MAX_CLUSTERS, (cId_t *)Project_ClusterList,
                                PROJECT_MAX_CLUSTERS, (cId_t *)Project_ClusterList,
                                FALSE );
          }
        if ( keys & HAL_KEY_SW_8 )
          {
            // Initiate a Match Description Request (Service Discovery)
            Project_SendTheMessage();
            //Yeu cau cap phat dia chi nwk dua tren dia chi ieee
            uint8 b = 0;
            
            ZLongAddr_t Addr64bit[8] = {0x26,0xDE,0xEF,0x02,0x00,0x4B,0x12,0x00};
            strcpy((char*)&(Project_DstAddr.addr.extAddr),(char*)&Addr64bit);
            b = ZDP_NwkAddrReq(Project_DstAddr.addr.extAddr,ZDP_ADDR_REQTYPE_SINGLE,0,0);
            if ( b == ZSuccess)
              HalUARTWrite(0x00,"Da yeu cau thanh cong dia chi\r\n", 30);
            else 
              HalUARTWrite(0x00,"Fail\r\n",5);
            //Yeu cau cap phat dia chi nwk dua tren dia chi ieee
            ZLongAddr_t Addr64bit2[8] = {0x00,0x12,0x4B,0x00,0x02,0xEF,0xDE,0x26};
            strcpy((char*)&(Project_DstAddr.addr.extAddr),(char*)&Addr64bit2);
            b = ZDP_NwkAddrReq(Project_DstAddr.addr.extAddr,ZDP_ADDR_REQTYPE_SINGLE,0,0);
            
            if ( b == ZSuccess)
              HalUARTWrite(0x00,"Da yeu cau thanh cong dia chi\r\n", 30);
            else 
              HalUARTWrite(0x00,"Fail\r\n",5);
            strcpy((char*)&(Project_DstAddr.addr.extAddr),(char*)&aExtendedAddress);
            b = ZDP_NwkAddrReq(Project_DstAddr.addr.extAddr,ZDP_ADDR_REQTYPE_SINGLE,0,0);
            if ( b == ZSuccess)
              HalUARTWrite(0x00,"Da yeu cau thanh cong dia chi\r\n", 30);
            else 
              HalUARTWrite(0x00,"Fail\r\n",5);
            ZDP_IEEEAddrReq(Project_DstAddr.addr.shortAddr,ZDP_ADDR_REQTYPE_SINGLE,0,0);
            
          }
    }
    
    /*********************************************************************
     * LOCAL FUNCTIONS
     */
    /*********************************************************************
     * @fn      Project_MessageMSGCB
     *
     * @brief   Data message processor callback.  This function processes
     *          any incoming data - probably from other devices.  So, based
     *          on cluster ID, perform the intended action.
     *
     * @param   none
     *
     * @return  none
     */
    static void Project_MessageMSGCB( afIncomingMSGPacket_t *pkt )
    {
      switch ( pkt->clusterId )
      {
        case PROJECT_CLUSTERID:
          rxMsgCount += 1;  // Count this message
    #if DEBUG
          HalUARTWrite(0x00,"-->Da doc duoc noi dung ban tin truyen den: \r\n",45);
          HalUARTWrite(0x00,pkt->cmd.Data,pkt->cmd.DataLength - 1);
    #endif
          HalLedSet ( HAL_LED_4, HAL_LED_MODE_BLINK );  // Blink an LED
          break;
      }
    }
    
    /*********************************************************************
     * @fn      Project_SendTheMessage
     *
     * @brief   Send "the" message.
     *
     * @param   none
     *
     * @return  none
     */
    static void Project_SendTheMessage( void )
    {
      char theMessageData[] = "Hello World";
    
      if ( AF_DataRequest( &Project_DstAddr, &Project_epDesc,
                           PROJECT_CLUSTERID,
                           (byte)osal_strlen( theMessageData ) + 1,
                           (byte *)&theMessageData,
                           &Project_TransID,
                           AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
      {
        // Successfully requested to be sent.
      }
      else
      {
        // Error occurred in request to send.
      }
      
    }
    
    
    /*********************************************************************
     */
    

  • Have I wrong while use 2 function ZDP_NwkAddrReq and ZDP_IEEEAddrReq???
    1. With function ZDP_NwkAddrReq . i import direct from keyboard as follows:
    ZLongAddr_t Addr64bit[8] = {0x26,0xDE,0xEF,0x02,0x00,0x4B,0x12,0x00};
    strcpy((char*)&(Project_DstAddr.addr.extAddr),(char*)&Addr64bit);
    b = ZDP_NwkAddrReq(Project_DstAddr.addr.extAddr,ZDP_ADDR_REQTYPE_SINGLE,0,0);
    2. With function ZDP_IEEEAddrReq i take from case Device_annce and case Match_Desc_rsp as file attach. And use:
    ZDP_IEEEAddrReq(Project_DstAddr.addr.shortAddr,ZDP_ADDR_REQTYPE_SINGLE,0,0);

    When init i register all :
    ZDO_RegisterForZDOMsg( Project_TaskID, End_Device_Bind_rsp );
    ZDO_RegisterForZDOMsg( Project_TaskID, Match_Desc_rsp );
    ZDO_RegisterForZDOMsg( Project_TaskID, IEEE_addr_rsp);
    ZDO_RegisterForZDOMsg( Project_TaskID, NWK_addr_rsp);
    ZDO_RegisterForZDOMsg( Project_TaskID, Device_annce);
    I hope receive your help, thanks you
  • Do you enable MT_ZDO_FUNC in your compile option?

  • Yes, i enable MT_ZDO_FUNC in compile.
    flag in compile:
    SECURE=1
    TC_LINKKEY_JOIN
    NV_INIT
    xNV_RESTORE
    ZTOOL_P1
    MT_TASK
    MT_APP_FUNC
    MT_SYS_FUNC
    MT_ZDO_FUNC
    MULTICAST_ENABLED=FALSE
    ZCL_READ
    ZCL_WRITE
    ZCL_REPORT
    ZCL_EZMODE
    ZCL_BASIC
    ZCL_IDENTIFY
    ZCL_ON_OFF
    ZCL_DIAGNOSTIC
    FEATURE_SYSTEM_STATS
  • I suggest you can try to use ZTool and MT command to test ZDP_NwkAddrReq.
  • Can Ztool run with SmartRf04EB??
    I run soft Ztool then receive table " No devices found"
    If Ztool can run with Smartrf04EB please guide me because i newbie
    Thanks you, Yikai Chen!
  • It should work. What baudrate do you set?
  • i haven't work Ztool. i need some day training with Ztool. i will feedback after have answer about ZDP_NwkAddrReq
    Thanks you YiKai chen
  • You are welcome!
  • Hi YiKai Chen,
    I use Z tool then receive: " No devices found"
    I fix MT_UARTInit() in MT_UART.c:
    flow control = FALSE
    Baud = 115200
    use ZTOOL_P1 and
    MT_TASK
    MT_APP_FUNC
    MT_SYS_FUNC
    MT_ZDO_FUNC
    Port setting: rate 115200,handshake = none..

    I connect to device PC use CP2102 with pin P0.2, P0.3 and GND


    Please where i wrong?

  • Do you select correct baudrate on ZTOOL?
  • Yes, i choise baud 115200