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.

  • The short address is 0x0000 but the cluster ID depends on your data. If it is for example temperature data, you should use temperature cluster ID.
  • Hi Yikai,

    here i have included sniffer log file. I am facing problem that device is getting disconnected from  the network after sometimes. I have attached part of my event handling code also which i suspect may be reason for this behaviour.

    #define TEMPERATURE_SENSING_EVENT       0XFF00
    
    //function for setting event when data is received at ZED
    void zb_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData )
    {
        osal_set_event ( sapi_TaskID, TEMPERATURE_SENSING_EVENT);	//setting event for sensing temperature
    }
    
    //function for event handling for ZED
    void zb_HandleOsalEvent( uint16 event )
    {
      uint8 *pData,sensor_data;
      if ( event & MY_START_EVT )
      {
        zb_StartRequest();
      }
     
      if ( event & MY_FIND_COLLECTOR_EVT )
      {
        // Find and bind to a collector device
        zb_BindDevice( TRUE, SENSOR_REPORT_CMD_ID2, (uint8 *)NULL );
      }
    
      if( event & TEMPERATURE_SENSING_EVENT)
      {
        sensor_data = 0x01;
        pData = "@TEM####" ;
        zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID2, 8, pData, 0, AF_ACK_REQUEST, 0 );//(for now using broadcast but will change at later stage
        event |= (event ^ TEMPERATURE_SENSING_EVENT);	//resetting temperature sensing event
      }
    }
    
    
    
    I had tried above handling event like this also but then also result is same
    
      if( event & TEMPERATURE_SENSING_EVENT)
      {
        pData = "@TEM####" ;
        zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, 8, pData, 0, AF_ACK_REQUEST, 0 );    
        event &= ~TEMPERATURE_SENSING_EVENT;	//resetting temperature sensing event
      }

    snif_log_23jan_7pm.psd

  • Hi Suyash,
    Can you please tell me which software is needed to open sniffer log(.psd) file. Or is there any converter file like .psd to pdf or .gif . If any such software is available then can you please share link for that.
    Thanks.
  • OSAL event uses bit flag on uint16. You can't define TEMPERATURE_SENSING_EVENT 0xFF00. You should define TEMPERATURE_SENSING_EVENT 0x0001.

  • 1) if its like so then can you please specify up to what range i can specify events(0x0001 to ?). i am asking because i need to use different sensors and sensor event.

    2)What about event handling code? which one is correct
    (a) event |= (event ^ TEMPERATURE_SENSING_EVENT); //resetting temperature sensing event
    or
    (b) event &= ~TEMPERATURE_SENSING_EVENT; //resetting temperature sensing event
  • 1. You can use 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, and 0x0080.
    2. b is correct one.
  • Hi Yikai,
    Thanks for your reply. Now the device is not getting disconnected. But if i use 0x0004 and 0x0008 as the event then that event occurs even if i am not requesting that event and it also occurs even if i clear that event after requesting. For all others what you had specified, event doesn't occur on its own unless and until requested. Do we have 8 values only?
  • You have to check if 0x0004 and 0x0008 are used in somewhere of simple app. According to simple app, you can use only 8 events.
  • Ya, 0x0004 and 0x0008 are being used for other events also.

    1) I don't have more knowledge about z-stack but if you don't mind why they have specified range for events as you can see below?

    Bit mask of events ( from 0x0000 to 0x00FF ) in SimpleSensor.c file

    Below are some definition of pre-defined events in z-stack and these are not defined by me.

    // Application osal event identifiers

    // Bit mask of events ( from 0x0000 to 0x00FF )

    #define MY_START_EVT                0x0001

    #define MY_REPORT_TEMP_EVT          0x0002

    #define MY_REPORT_BATT_EVT          0x0004

    #define MY_FIND_COLLECTOR_EVT       0x0008

    These events are also pre-defined in z-stack in hal_drivers.h file

    #define HAL_KEY_EVENT 0x0001
    #define HAL_LED_BLINK_EVENT 0x0002
    #define HAL_SLEEP_TIMER_EVENT 0x0004
    #define PERIOD_RSSI_RESET_EVT 0x0008

    2)Why they have defined two events as you can see above with same value? Is it due to two events are defined in seperate files or for two different layers(HAL and OSAL) so there is no problem with its use.

    3)So will these events not disturb other event if i use 0x0001,0x0002?

    Thanks

  • OSAL and HAL event are irrelevant so you can see the same value assigned to different event. The limitation of 8 events is only in Simple App because it reserves top 8 bit flags as internal uses.
  • Hi Yikai,
    Which application i should use if number of events required in my application is more than 30. I am not able to understand why we can't use 0x0003,0x0005,0x0006,0x0015 etc. Is it because while resetting event, other event's bit will get cleared?
  • The event mechanism uses bit flag and every bit in the bit flag means different event. If you use 0x0003 which is 0x0001 | 0x0002, that means there are two events.
  • So, even if we are allowed to use 16 bits of osal events(0x0001,0x0002,0x0004-0xf000) in some application other than simple app then how these 16 bits will be enough to handle various parameters in an industry where a zigbee device has to control various parameters like temperature,pressure,humidity,voltage,current and several other. My application also require several events like this then how can i do this?
  • Sorry. Typing mistake. i meant osal events(0x0001,0x0020,0x0400-0xf000) in my previous post
  • In Simple App, it reserves high right bits for internal use so you only have 8 events to use.
  • I know this as you had replied this thing in your earlier posts(possible events in simple app 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, and 0x0080). i want to know whether any application is there in z-stack like home automation,sample app or any other than simple app in which i can use more events and not only 8. In my application i require around 30 events and if event mechanism uses bit flag then more than 16 events are not possible which is not enough for my application.
  • In Z-Stack Home example, there are about 4 events of 16 to total are used by home automation profile features, such as identify event, EZ-mode event,...Maybe you can explain to me why you need 30 events and I try to give you alternative.
  • I want to control sony HD camera through remote using zigbee. As you know there are several events in controlling camera like camera on,off, zoom+,zoom-, white balance,focus+,focus- etc. If i calculate these events then i will get around 30 events like this.
  • In this kind of application, I don't see why you have to use some many events. You can create attributes for all this different action types. When you receive a command to write an attribute, you can trigger the action directly.
  • I don't know what do attributes mean. I had searched for it but couldn't get satisfactory answer.
    Can you please site some example? Up to my understanding, you mean to define these actions like

    #define CAMERA_ON 0x05 //(for example)
    #define CAMERA_OFF 0x06

    void zb_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData ) //read command received from remote to the
    camera module
    {
    switch(pData[0]) //pData[0] contains command sent from remote(suppose)
    {
    case CAMERA_ON:
    //process for switching camera ON
    .
    .
    I can do like this also.
  • You should read ZCL spec for understanding Zigbee attribute and cluster.
  • Hi Yikai,

    Here i have included sniffer log file of communication in between coordinator and philips hue. As you can see in the log file the hue is constantly and repeatedly sending beacon request, short address is being assigned to the hue but end point request and response is not made. I had tried to debug but control doesn't come to either of the three cases case Device_annce:, case Active_EP_rsp:,case Simple_Desc_rsp: .

    Can you please suggest some idea how to troubleshoot it. Which application is required for communicating with these types of devices(readymade)?

    Thanks

    snif_log_28Jan15_11am.psd

  • Hi Yikai,
    i do remember that procedure for communicating with devices(ready made) are same as normal like device announce,EP request and response,simple descriptor request and response and device should follow zigbee HA profile. But unless control reaches case Device_annce: how can coordinator send EP request? I am not able to think why device announce is not taking place although source address is assigned to the hue as can be seen in sniffer log.
    Is there any standard application(for handling these types of ready made devices) which defines cluster ids for these standard devices? i don't know what should be the commands for switching these lights ON and OFF. I do believe that there will be some standard commands for handling these types of devices.
    Thanks.
  • In my test on Philips Hue, I can receive end node announcement on my ZC. You should set a breakpoint to see why you don't receive end node announcement in your ZC.
  • Hi Yikai,
    Can you please suggest how end device can be binded in simple app without switch press. In simple app, switch is required to configure the device as end device but i want the device should configure on its own because there is no switch in some of my hardware. I want to know where(which function) i need to add handle key part of code to configure the device as end device.
    Thanks
  • Using SampleSwitch as example, you can revise ZDO_STATE_CHANGE in zclSampleSw_event_loop() to send end device binding like the followings:

    case ZDO_STATE_CHANGE:
    zclSampleSw_NwkState = (devStates_t)(MSGpkt->hdr.status);

    // now on the network
    if ( (zclSampleSw_NwkState == DEV_ZB_COORD) ||
    (zclSampleSw_NwkState == DEV_ROUTER) ||
    (zclSampleSw_NwkState == DEV_END_DEVICE) )
    {
    // bind to remote light
    zAddrType_t dstAddr;
    HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );

    // Initiate an End Device Bind Request, this bind request will
    // only use a cluster list that is important to binding.
    dstAddr.addrMode = afAddr16Bit;
    dstAddr.addr.shortAddr = 0; // Coordinator makes the match
    ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(),
    SAMPLESW_ENDPOINT,
    ZCL_HA_PROFILE_ID,
    0, NULL, // No incoming clusters to bind
    ZCLSAMPLESW_BINDINGLIST, bindingOutClusters,
    TRUE );
    }
    break;
  • Thanks a lot for your response. Now my devices are communicating without any need of switch for binding. Is there any restriction we need to keep in mind for assigning our device cluster_id,profile_id etc? I mean to say do these parameters need to be assigned value based on bit logic or we can assign these on our wish.
  • For those details, you should read Zigbee HA and ZCL spec.
  • Can you please specify related documents?
  • Hi Yikai,
    Can you please suggest for the following are the errors(its not related to zigbee).i am getting following errors and my program is not getting downloaded in CC2530.
    Warning: Flash page 0 is locked and was not written to.
    .
    .
    Warning: Flash page 64 is locked and was not written to.
    Warning: Skipped verification on page 0 due to lock bits.
    Warning: Verification error on page #1, address range 0x00800 - 0x01000, address 0x00803, 0x08 (on target) != 0x09 (in object file).
    etc.
    What may be possible cause for these type of errors?
    I don't know why my all previously tested program are not working even though i didn't make changes in both hardware and software. i have tried by testing with different hardwares and previously tested softwares but none of them are working. With most sofwares end device is not sending beacon request.
  • Try to use flash programmer to erase CC2530 and download FW again.
  • I had tried by erasing and then downloading my program but it doesn't solve the problem. Same error i get for all the codes i am trying to download. What do you mean by "download FW again"? do you mean to program cc2530 after erashing using flash programmer or something else?
  • Yes, I mean to program CC2530 after erasing using flash programmer. Do you try to install a new z-stack to build and download example to see if it works?
    • Ya, i had tried to download new z-stack example code but result is same. here i have included snapshot of setting for erasing flash. Do i need to erase secondary memory also?   

  • Do you try to download the same FW to another HW? It might be CC2530 flash broken.
  • I too think there is problem with flash because same program is getting downloaded in other hardware. What may be possible cause of flash failure? Is it programming it again and again? secondary memory should be erased or not?
  • Programming CC2530 again and again shouldn't damage the flash. Is it possible that you give wrong voltage input to VDD of CC2530 and damage it?
  • No, I have always used ccdebugger to power it and was working with same setup before. Some other cause may be there.
  • Maybe…Anyway, it seems the HW is broken and you have to replace it with another new.
  • Hi Yikai,
    Can you please suggest me what i need to check if my device is not sending beacon request? Is it anyhow related to hardware pin configuration as i/p or o/p?
    Thanks
  • Can you describe your more specific? If this is a new issue and not related to this thread topic, can you open a new one?
  • These days I am struggling a lot as so many of my previously tested programs are not working with different hardware. With all these codes i had tested for binding and data transmission but now its not working even its not sending beacon request also. All these hardwares are sending beacon request with z-stack home automation code. so i don't think there should be hardware problem. I am not able to figure out where may be problem.
  • Do you mean you can't see beacon on your modified example?
  • Ya. I had modified simple app code. I had tested and verified for binding and communication with same modified code. But now none of these codes are sending even beacon request. I have changed hardware and tested home automation code in this hardware. With this home automation code its sending beacon request but not with my modified code.
    I had tried to debug. "SYS_EVENT_MSG" event in "UINT16 SAPI_ProcessEvent( byte task_id, UINT16 events )" doesn't occur which i think is responsible for sending beacon request. This function is executed only once and at that instance also " if ( events & SYS_EVENT_MSG )" condition is false.
  • Do you enable NV_RESTORE in your test? If so, disable and test again.
  • I had tested by removing NV_RESTORE. But it doesn't solve the problem.
    When i am testing modified code(even using NV_RESTORE) with my old hardwares then same program is working fine but with new hardwares(even after removing NV_RESTORE) it doesn't work. My old and new hardwares have different connections like port pins are connected differently in old and new hardware.
    Is sending beacon request related to hardware pin configuration?
    In one of my hardware if i download coordinator code(of simple app) then it works fine but end device code doesn't send beacon request.
  • So, your program still runs well on old HW, right? You can try to debug and see if your end device program stuck in ZDAppCheckForHoldKey() in ZDApp.c using new HW.

  • Ya, my all programs are running fine in old hardwares. i had tried to debug at ZDAppCheckForHoldKey(). It doesn't stuck at this function and executes next statement. For sometimes i may think that it may have problem in my new hardware but i have tested home automation code which sends beacon request and gets binded also.
  • I had left my new device powered on for last one hour and sniffer captured some data. here i have included sniffer log file for my new device. I don't know what it is. May be you can get something from it. my device is configured as end device.

    a.psd