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 znp uart program flow

Other Parts Discussed in Thread: Z-STACK, CC2530, CC2530EM, CC2531

Hi Everyone,

                  I am working on home automation project and new to zigbee. Right now i am using ZNP code available in(ZStack-CC2530-2.5.1a_1\Projects\zstack\ZNP\cc253x\znp iar ide workspace). I am able to understand uart initialization but I am not able to understand the program flow sequence for sending and receiving data using uart dma(like which function to call for reading data sent through uart). I am using usart0 with default baud rate of 115200.

Can anybody please help me regarding this.

  •  Hi Yikai,

    I am finding problem in extracting end point after end point response because i don't know what will be value for " j" in pActiveEPs->epList[j] . Can you please tell me how i can get endpoint from pActiveEPs and store it in device_list[0].endpoint

    typedef struct
    {
    uint16 nwkAddr; // Network address
    uint8 endpoint; // Endpoint identifier
    uint16 profileID; // Profile identifier
    uint16 deviceID; // Device identifier
    uint8 version; // Version
    } epInfoRec_t;
    extern epInfoRec_t device_list[10];

    void SAPI_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
    {
       switch ( inMsg->clusterID )

       {

           .

           case Active_EP_rsp:
           {
              ZDO_ActiveEndpointRsp_t *pActiveEPs = NULL;
              pActiveEPs = ZDO_ParseEPListRsp( inMsg ); //get end point response
              if ( pActiveEPs->status == ZSuccess )
              {

                 device_list[0].endpoint = pActiveEPs->epList[j];

                  .

              }    //if condition ends here

           } //case ends here

       }//switch case ends here

    }//function ends here

    I am using simple app z-stack Version 2.5.1a

  • Do you have multiple endpoints on device? If not, j can be always 0.
  • ya, 8 end points are there. How can i know active epoint response came for which end device
  • Here i have included my code for storing device address in array. I have doubt only in "case Active_EP_rsp:" whether its correct or not.

    const cId_t zb_InCmdList[NUM_IN_CMD_COLLECTOR] =
    {
      TEMPERATURE_SENSOR_CMD_ID  				//temperature sensor IN cluster(defined in respective sensor file)
    };
    const cId_t zb_InCmdList[NUM_IN_CMD_COLLECTOR] =
    {
      PIR_SENSOR_CMD_ID					//pir sensor IN cluster(defined in respective sensor file)
    };
    const cId_t zb_InCmdList[NUM_IN_CMD_COLLECTOR] =
    {
      ENERGY_METER_CMD_ID  					//energy meter IN cluster(defined in respective sensor file)
    };
    
    #define PIR_SENSOR_ENDPOINT_ID            0x02
    #define ENERGY_METER_ENDPOINT_ID          0X02 
    #define TEMP_ENDPOINT_ID                  0x02
    
      
    uint8 dev_cnt;
                
    	case Device_annce:
            {          
              ZDO_DeviceAnnce_t devAnnce;
              ZDO_ParseDeviceAnnce( inMsg, &devAnnce );
              destAddr.addrMode = Addr16Bit;
              destAddr.addr.shortAddr = devAnnce.nwkAddr;
              for(dev_cnt =0;dev_cnt<10;dev_cnt++)  //check whether any device with short address same as devAnnce.nwkAddr is already present or not
              {
                if(destAddr.addr.shortAddr == device_list[dev_cnt].nwkAddr)
                {
                  break;    //break loop if device is already registered
                }
              }
              if( dev_cnt == 10)    //dev_cnt == 10 means device is not registered in the device list,dev_cnt<10 means device already present in list
              {
                for(uint8 i = 0;i < 10;i++)
                {
                  if(device_list[i].endpoint == NULL)  //check which is the last device registered, endpoint with NULL means no device registered at that device list
                  {
                    device_list[i].nwkAddr = devAnnce.nwkAddr;             //register short address of the announced device into device list at location where device is not registered
                    ZDP_ActiveEPReq( &destAddr, devAnnce.nwkAddr, 0);   //send active end point request for the new device announced
                    break;  //exit further registering of devices
                  }
                }
              }            
            }
            break;
          case Active_EP_rsp:
            { 
              ZDO_ActiveEndpointRsp_t *pActiveEPs = NULL;
              pActiveEPs = ZDO_ParseEPListRsp( inMsg );     //get end point response         
              if ( pActiveEPs->status == ZSuccess )
              {
                for (uint8 j=0; j < pActiveEPs->cnt; j++ )  //
                {
                  if(pActiveEPs->nwkAddr == device_list[j].nwkAddr)    //match the short address of the end point for which end point response has arrived
                  {
                    device_list[j].endpoint = pActiveEPs->epList[j];   //store the end point of the responded end point in the device list
                    addr.addr.shortAddr = pActiveEPs->nwkAddr;
                    addr.addrMode = Addr16Bit; 
                    ZDP_SimpleDescReq( &addr, pActiveEPs->nwkAddr, pActiveEPs->epList[j], 0 );   //send simple descriptor request to the responded end device
                    break;  //exit from further request
                  }
                }
                if ( pActiveEPs != NULL )
                {
                  osal_mem_free( pActiveEPs );      //free memory
                }
              }
            }
            break;
          case Simple_Desc_rsp: 
            {
              ZDO_SimpleDescRsp_t simpleDescRsp;
              simpleDescRsp.simpleDesc.pAppInClusterList = simpleDescRsp.simpleDesc.pAppOutClusterList = NULL;        
              ZDO_ParseSimpleDescRsp( inMsg, &simpleDescRsp );
              if((simpleDescRsp.simpleDesc.pAppInClusterList[0] == TEMPERATURE_SENSOR_CMD_ID) && (simpleDescRsp.simpleDesc.EndPoint == TEMP_ENDPOINT_ID))   //match clusterid and endpoint to store short address in array
              {
                device_list[0].nwkAddr = simpleDescRsp.nwkAddr;     //store short address in array
              }
              else if((simpleDescRsp.simpleDesc.pAppInClusterList[0] == PIR_SENSOR_CMD_ID) && (simpleDescRsp.simpleDesc.EndPoint == PIR_SENSOR_ENDPOINT_ID))
              {
                device_list[1].nwkAddr = simpleDescRsp.nwkAddr;
              }
              else if((simpleDescRsp.simpleDesc.pAppInClusterList[0] == ENERGY_METER_ENDPOINT_ID) && (simpleDescRsp.simpleDesc.EndPoint == ENERGY_METER_ENDPOINT_ID))
              {
                device_list[2].nwkAddr = simpleDescRsp.nwkAddr;
              }
    
              if ( simpleDescRsp.simpleDesc.pAppInClusterList != NULL )     //free memory if not empty
              {
                osal_mem_free( simpleDescRsp.simpleDesc.pAppInClusterList );
              }
              if ( simpleDescRsp.simpleDesc.pAppOutClusterList != NULL )
              {
                osal_mem_free( simpleDescRsp.simpleDesc.pAppOutClusterList );
              }          
            }               
            break; 

  • If you have 8 endpoint on a device, there will be 8 endpoints in pActiveEPs->epList and all from the same short address.
  • I couldn't get this "there will be 8 endpoints in pActiveEPs->epList and all from the same short address." How all 8 eplist will be from same short address if different end device have different short address?
  • Maybe I misunderstand you. Let me ask again. How many endpoint do you support on a device? 1 or 8?
  • 8 end device will be communicating with coordinator.
  • It looks like you have 8 end devices and each one only support 1 active endpoint. You should revise your Active_EP_rsp case like the followings in red.

         case Active_EP_rsp:

           {

             ZDO_ActiveEndpointRsp_t *pActiveEPs = NULL;

             pActiveEPs = ZDO_ParseEPListRsp( inMsg );     //get end point response        

             if ( pActiveEPs->status == ZSuccess )

             {

               for (uint8 j=0; j < 10; j++ )  //

               {

                 if(pActiveEPs->nwkAddr == device_list[j].nwkAddr)    //match the short address of the end point for which end point response has arrived

                 {

                   device_list[j].endpoint = pActiveEPs->epList[0];   //store the end point of the responded end point in the device list

                   addr.addr.shortAddr = pActiveEPs->nwkAddr;

                   addr.addrMode = Addr16Bit;

                   ZDP_SimpleDescReq( &addr, pActiveEPs->nwkAddr, pActiveEPs->epList[j], 0 );   //send simple descriptor request to the responded end device

                   break;  //exit from further request

                 }

               }

               if ( pActiveEPs != NULL )

               {

                 osal_mem_free( pActiveEPs );      //free memory

               }

             }

           }

  • So you mean to say pActiveEPs->epList[0] will be having the end point of the notified end device no matter how many end devices are there. Will there be problem if active response comes from two end devices. i mean to say if two devices are powered on at the same time in that case active end point response may come from any of the two device.
  • Even two end devices are turned on at the same time, end node announcement and active end point response would come one by one. Since you use if(pActiveEPs->nwkAddr == device_list[j].nwkAddr) to check short address, it means that you know where the endpoint comes from. Why do you always think you can't match short address and endpoint?
  • i know that if(pActiveEPs->nwkAddr == device_list[j].nwkAddr) will check active end point response came from which device.

    1)I don't know more but i was having doubt if 0th location in epList[0] will hold the endpoint for different end device no matter how many end device are there

    2)if response came from some other end device then this condition if(pActiveEPs->nwkAddr == device_list[j].nwkAddr) will fail and end point will not be stored. So will two end device again send response so that endpoint is stored next time?

  • You request for active endpoint one by one with short address so endpoint response would receive endpoint of different devices one by one.
  • Ya i got now. Will verify these tomorrow
    thanks
  • Hi Yikai,
    Thanks for your support. Now multiple devices are communicating simultaneously and there is no interference what i was getting earlier.
    Is there any way by which i can know which are the devices currently in the network? If any device leaves network then i want to clear the device_list array for that particular end device.
  • How does your device leave network? Will you delete it or??
  • When end device is powered off and powered on again then coordinator will assign new short address which will not be in device list. So this way array will get full and as array size is 10 then no new short address can be stored as it checks whether end point is null or not. So i am thinking to delete the end device information from device list if it leaves network. On way is to use NV_RESTORE using which no new short address can be assigned and it will be fixed for particular end device but now i am thinking not to use NV_RESTORE.
  • In your application, I suggest you using NV_RESTORE. In this way, the short address won't change after you do power recycle to any devices.
  • I too think to use it but as i had already told some of my new hardwares are not working. What i suspect(i may be wrong) reason is i had used NV_RESTORE and then i wanted to delete the stored information in non volatile memory as after reprogramming it was not getting binded. So for that i used to erase the flash using flash programmer. After that devices were not sending beacon request at all. So i think not to erase the flash unless and until needed. As three to four hardwares are non working i don't want to take risk as i am goint through testing stage in which i need to program again and again. In my final application i will use NV_RESTORE.
  • I don't think NV_RESOTRE is related to your hardware not working. I suggest you dig into it and find the root cause.
  • I am not saying its problem with using NV_RESTORE. I am saying erasing flash again and again may be the reason. I will try to find if any other cause is there.
    In my next application i want to control phillips hue. Which z-stack application will be better to use for it. It will be better if i can do it with simple app itself as i am able to understand it more clearly and know the flow.
  • When Philips Hue is factory reset, it would send beacon to join HA network first. If you want to integrate it, I would suggest HA profile.
  • With my same FW, I could see in sniffer log that phillips hue is sending beacon request and it is assigned short address. I will use HA profile and check whether i can control it or not. Meanwhile if i am right then by HA profile u mean to use cluster ids and other parameters of HA profile in same simple app what i am using.
  • The most important is profile ID has to be HA profile.
  • HI Yikai,
    Here are the definitions of parameters for communicating with Phillips hue
    #define PHILLIPS_HUE_PROFILE_ID 0x0104 //HA profile id
    #define PHILLIPS_HUE_ON_OFF_CMD_ID 0x0006 //cluster id
    #define PHILLIPS_HUE_DEV_ID 0x0100 //device id
    #define PHILLIPS_HUE_SWITCH_ON 0x01 //command for switching light on
    #define PHILLIPS_HUE_SWITCH_OFF 0x00 //command for switching light off
    1) What end point i need to assign to the coordinator(i have used 0x02 as end point)
    2)In sniffer log i can see that after beacon request from end device(phillips hue), short address is assigned to it but again beacon request comes from end device and short address is assigned again. This process repeats. I had tried to debug by placing breakpoint at device annce case but control doesn't reaches there. Am i missing anything? I am using simple app.
  • Do you enable SECURITY with TC_LINK_KEY on your Zigbee network?
  • I am not sure whether its enabled or not. i didn't make any changes for security in original z-stack simple app. I had tried but failed to place breakpoint at void APSME_TCLinkKeyInit(uint8 setDefault) where that variable is used. i am not using NV_RESTORE which is used in this function.
  • If you want to integrate Philips Hue, you have to use HA profile in which SECURITY and TC_LINK_KEY are mandatory.
  • 1)Can you please tell how to enable these?
    2)Is there necessity to reset the hue using remote before it joins the network? I don't have that.
  • 1. Change SECURE=1 in f8wconfig.cfg and define TC_LINK_KEY in your project option.
    2. Yes, it is must to do factory reset.
  • Will the light not be factory resetted? If i don't have remote then is there other way to communicate with it?
  • No, I think you have to buy a remote controller to reset it.
  • If you know can you please tell where i can buy it from and what will be specification for it? Will remote be seperately available?
  • I had inquired with several service provider but they are telling it will work only with their coordinator and not ours. So even if i buy it,it will be waste of money. I can buy any zigbee device if and only if it works with my coordinator.
  • I am pretty sure it works on our GW after I do a factory reset to Philips Hue. They say no because they don't have enough knowledge on it.
  • Don't you know any link where i can get this remote?
  • Hi Yikai,
    I think you may not know the supplier or web link where i can get the remote. I will try to ask in general forum about the specification and vendor who can provide it. Its urgent for me.
    Are you sure if i buy any such zigbee based remote then it will work with my coordinator and phillips hue? i am asking because every manufacturer may have their own concept of programming such devices that may not follow HA profile.
  • I make my own remote controller to reset hue and don't know where you can buy one on the market. You can refer to discussions at community.smartthings.com/.../3323
  • Sorry to use word panic. I didn't know its meaning before. Thanks for your continuous support. With the help and support i have got from you till yet i have been able to control different sensors using android app and close to finishing my application. Only thing remaining is communicating with third party zigbee devices like phillips hue which i don't know how i will finish unless i get remote.
  • You can buy ZLight kit from . It demonstrates ZLL profile and is the same to Philips Hue.

  • Hi Yikai,
    1)Will this remote work with my coordinator?
    2)If i have 15 lights in network then will this one remote can handle all?
  • I don't know if TI's remote controller can reset Philips Hue. I mean you can buy ZLL light kit and use it instead of Philips hue for your project. There is a button on TI ZLL light and you can press and hold it for more than 5 seconds to reset ZLL light.
  • Can you please suggest how i can interface analog accelerometer? For accelerometer we need to read adc continuously and if there will be movement then adc will change. If adc changes, i need to inform coordinator about the movement. I am finding problem that i can't use while loop to do the above operation as doing this will make end device out of network. Can you please suggest how can i proceed? One way i think is to use timer to sense adc every 2 or 5 sec but if movement occurs in between period then it will not be able to detect. Is there other way to do this?
  • If your application is powered by battery, it is very power consuming to keep doing ADC reading. I would suggest you using digital type accelerometer.
  • 1)I will be using digital one only but for now i need to interface analog. Is it possible by assigning task in tasksarr?
    2)If i use power saving mode then will digital accelerometer generate interrupt when there will be movement?
  • If you have to use analog one, you can try to start a periodic event to do that, e.g. wake up every 200ms to read analog input from accelerometer.
  • Sorry. I think using Auto wake/sleep mode, interrupt can generate even if it is in power saving mode.
  • A periodic event is interrupt driven and will wake up device from sleeping mode periodically.

  • Ok, I will contact them and find if it works. If i use power saving mode at end device end then is there any way by which coordinator can wake up end device? i want to keep temperature sensor in sleep mode and want to wake it up by sending some command from coordinator. Is it possible?
  • For end device, it uses polling to get message. You have to set proper polling rate to receive message from coordinator.