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.

  • I only see one beacon in the log and nothing special. I suggest you debug on your new HW and check what is the value of devState when device doesn't do beacon.

  • I will check that.
    by the way what type of error is this? I have verified there is no any function or variable named "ep" in either of two files "SimpleSensor.c" and "ZMain.c"
    Linking
    Error[e27]: Entry "ep" in module SimpleSensor ( D:\Narendra\zigbee\Projects\zstack\Samples\SimpleApp\CC2530DB\SimpleSensorEB\Obj\SimpleSensor.r51 ) redefined in module
    ZMain ( D:\Narendra\zigbee\Projects\zstack\Samples\SimpleApp\CC2530DB\SimpleSensorEB\Obj\ZMain.r51 )
    Error while running Linker
  • I don't know. Where do you get this SimpleSensor? When you post issue next time, please specify what Z-Stack you use so I can understand it better.
  • Through whole of my discussion till yet i am using "simple app" "z-stack Version 2.5.1a". i don't think its related to z-stack. i only want to know when this type of error(Error[e27]: ) comes. I am getting this error in my modified code and not original z-stack.
  • Check if you define any structure in header file SimpleSensor.h? If so, try to move it to SimpleSensor.c.
  • Sorry! i got reason for it. I had defined variable "ep" in some other header file and included this header file in both "SimpleSensor.c" and "ZMain.c". Twice this header file is getting included indirectly in these two files. that's why it shows that error.
  • It's good to help you find the problem.
  • Sorry for wrong explanation in my previous post. I hadn't declared "ep" variable in its header file as "extern" but was using that as global variable in two files(a.c and b.c suppose by including that header file). The same header file i had included in other two files "ZMain.c" and "SimpleSensor.c" for using functions defined in that header file. That's why it was showing error in ZMain.c and SimpleSensor.c file.
    Now i have declared variable as extern and redeclared it in one file and now i am not getting that error.
  • What to do if i want to keep my end device always powered on(wake up) and it should not go to sleep mode ant any moment
  • Just disable POWER_SAVING in compiler option.
  • Hi Yikai,
    1)Can you please explain what's problem with using NV_RESTORE. I think its better to use if we want to retain the end device address. If i use NV_RESTORE then the end device doesn't get binded but disabling it results in binding. Why it happens?
    2)Should i use NV_RESTORE in coordinator end only or end device end also?
    Thanks
  • 1. Binding is controlled by application and nothing to do with NV_RESTORE.
    2. You have to enable NV_RESTORE on both coordinator and end device.
  • Hi Yikai,

    Here is my own interrupt routine at port P1.2. My problem is that interrupt occurs continuously from start as its powered ON even though there is no voltage change or noise present at this port. i have checked with oscilloscope.. can you please suggest if i am missing anything.

    P1SEL &= ~0x04;	//set P1.2 as GPIO
    P1DIR &= ~0x04; // set P1.2 as input
    
    /* PIR sensor is connected to port P1.2*/
    #define PIR_SENSOR_PORT       P1	
    #define PIR_SENSOR_BIT        BV(2)         
    #define PIR_SENSOR_SEL        P1SEL
    #define PIR_SENSOR_DIR        P1DIR
    
    #define HAL_KEY_RISING_EDGE   0
    
    /* edge interrupt */
    #define PIR_SENSOR_EDGEBIT    BV(1)
    #define PIR_SENSOR_EDGE       HAL_KEY_RISING_EDGE
    
    
    #define PIR_SENSOR_IEN       IEN2  /* CPU interrupt mask register */
    #define PIR_SENSOR_IENBIT    BV(4) /* Mask bit for all of Port_1 */
    #define PIR_SENSOR_ICTL      P1IEN /* Port Interrupt Control register */
    #define PIR_SENSOR_ICTLBIT   BV(2) /* P1IEN - P1.2 enable/disable bit */
    #define PIR_SENSOR_PXIFG     P1IFG /* Interrupt flag at source */
    #define PIR_SENSOR_CPU_PORT_1_IF     P1IF
    
    void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)
    {
    .
    .
        PICTL &= ~(PIR_SENSOR_EDGEBIT);     //clear edge bit for pir sensor
        #if (PIR_SENSOR_EDGE == HAL_KEY_FALLING_EDGE)
          PICTL |= PIR_SENSOR_EDGEBIT;
        #endif
        PIR_SENSOR_ICTL |= PIR_SENSOR_ICTLBIT;
        PIR_SENSOR_IEN  |= PIR_SENSOR_IENBIT;
        PIR_SENSOR_PXIFG &= ~(PIR_SENSOR_BIT);
    .
    .
    }
    
    HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR )
    {
      HAL_ENTER_ISR();
      if(if (PIR_SENSOR_PXIFG & PIR_SENSOR_BIT)
      {
        .
        .
      }
      PIR_SENSOR_PXIFG = ~(PIR_SENSOR_BIT);
      PIR_SENSOR_CPU_PORT_1_IF = 0;
      
      CLEAR_SLEEP_MODE();
      HAL_EXIT_ISR();
    
    }
    

  • Before i was configuring port(using P1SEL &= ~0x04;P1DIR &= ~0x04;) as input in hal_board_cfg.h

    Adding following lines(marked in bold) solved the problem. It may be that before port would not have got configured properly (in hal_board_cfg.h).

    void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback)

    {

    .

    .

       PIR_SENSOR_SEL &= ~(PIR_SENSOR_BIT);

       PIR_SENSOR_DIR &= ~(PIR_SENSOR_BIT);

       PICTL &= ~(PIR_SENSOR_EDGEBIT);     //clear edge bit for pir sensor

       #if (PIR_SENSOR_EDGE == HAL_KEY_FALLING_EDGE)

         PICTL |= PIR_SENSOR_EDGEBIT;

       #endif

       PIR_SENSOR_ICTL |= PIR_SENSOR_ICTLBIT;

       PIR_SENSOR_IEN  |= PIR_SENSOR_IENBIT;

       PIR_SENSOR_PXIFG &= ~(PIR_SENSOR_BIT);

    .

    .

    }

  • You shouldn't do PIR_SENSOR_PXIFG = ~(PIR_SENSOR_BIT) in HAL_ISR_FUNCTION( halKeyPort1Isr, P1INT_VECTOR ). It should be PIR_SENSOR_PXIFG =0.
  • If i am not wrong then PIR_SENSOR_PXIFG =0 means P1IFG=0 which will clear interrupt for all port pins(P1.0-P1.7) but PIR_SENSOR_PXIFG = ~(PIR_SENSOR_BIT) will clear interrupt for only port P1.2.

    I think I was getting that error because my port pins were not configured properly in "hal_board_cfg.h". so i had reconfigured it in void HalKeyConfig (bool interruptEnable, halKeyCBack_t cback) function as PIR_SENSOR_SEL &= ~(PIR_SENSOR_BIT); PIR_SENSOR_DIR &= ~(PIR_SENSOR_BIT); and problem was solved.
  • OK, it is good to know your problem is solved again.
  • Hi Yikai,
    I do understand importance of understanding ZCL specifications for assigning cluster id which i must understand for creating a zigbee network. Since it has around 400 pages it will take me some time to understand them. Till now i have been able to communicate with different sensors using simple app of "z-stack Version 2.5.1a". But for all these testing i had used same end device configurations as provided in original z-stack.
    Now i need to organize and configure all these sensors with unique ids so that data sent to one device doesn't affect other device.
    How can i differentiate these sensor devices from one another? I can store device information like their short address,end point etc in array after end device notification but i don't know where to assign these parameters(excluding short address) for different end devices. after device announce i need to request for endpoint which will be known by device response but i don't know what end point i should set for different sensors and whether they follow bit logic.

    So if you can please provide me just hint how to assign these parameters like what parameters should be different for different sensors,whether these parameters follow bit logic etc then i can proceed further easily. I am keeping my network as simple for now like there will be one coordinator and 8 end devices and communication will only take place in between coordinator and end device and not among end devices.
    Thanks
  • I think this is about how your application is. The application should keep all ZB related information, such as short address, IEEE address, device type, active endpoint and simple descriptor. Then, your application knows how to send command or do something.
  • As far as i know IEEE address is defined by manufacturer(ti CC2530) and short address is assigned by coordinator. So no need to think about these two. So
    1) if i keep different profile id,endpoint,device id,device version(defined in SimpleApp.h) then will it be enough to distinguish different sensors.
    2)Is there range limitation in its definition for above mentioned parameters?
    3)Do these parameters follow bit logic or i can assign values based on my choice.
  • 1. Yes. but I think you miss simple descriptor which is very important information.
    2. What do you mean range limitation?
    3. These parameters are well defined in ZCL spec and you should follow it.
  • typedef struct
    {
    uint8 EndPoint;
    uint16 AppProfId;
    uint16 AppDeviceId;
    uint8 AppDevVer:4;
    uint8 Reserved:4; // AF_V1_SUPPORT uses for AppFlags:4.
    uint8 AppNumInClusters;
    cId_t *pAppInClusterList;
    uint8 AppNumOutClusters;
    cId_t *pAppOutClusterList;
    } SimpleDescriptionFormat_t;
    I think by simple descriptor you are talking about pAppInClusterList and pAppOutClusterList which i will be definitely adding.
    By range limitation i meant like endpoint should be in range 0-255 or 0-16(for example)
  • I will follow ZCL specification for these parameters but i have one doubt that how we can define these parameters if same type of sensors or end devices are present like if we need to control 5 lights,3 temperature sensors. In these case how can we distinguish in between different end devices
  • For endpoint, the range is 1-240.
  • If you have several same devices, you can give them a name or label a number to each of them. In such way, you can distinguish them.
  • naming we can give whatever we want(but its best and understandable to follow ZCL specification) for distinguishing that's not big thing. what i meant is in such cases what different values we should assign so that no two devices get affected with other. What i mean is if there are five lights in a room and if we keep same cluster ids then it will affect all other lights other than intended. In these case what we should do.
  • This is not defined by Zigbee spec. It is all about application layer. If you want to control different light, you must label them first. For example, you have to label living room light, bedroom light, ...etc in your device list and you can know which one you want to send ON/OFF command when you want to turn on or off the light in somewhere.
  • So you mean to say same value of cluster id(as per ZCL spec) should be assigned to all these living room light, bedroom light, ...etc and we can distinguish them by camparing them with their name.
    For example if cluster ids are assigned like this # define living_room_light =1 and #define bedroom_light =1 and if coordinator sent ON command with cluster value living_room_light then will bedroom_light not get on as they have same cluster ids?
  • As far as i think during transmission hex value is sent and not their lable. At the other side it will be comparing whether hex vale is same or not. So during comparision any of two labels(device) with same hex value may match and that can process after that.
  • No, this should be done on coordinator if you put application on coordinator. When use wants to turn on living room light, you should search it in device list and find the short address and active endpoint of living room light to send ON command.
  • Ok Ok. thanks a lot for clear explanation. now i got that. In ZCL spec i can't find end points,profile ids etc other than cluster ids and some commands(ZCL.h in Z-Stack Home 1.2.1). Are these parameters defined somewhere else?
  • I had searched in ZCL spec pdf document also what you had given in this link but i can't find any of the simple descriptor definitions here except few commands for each sensor types. Zigbee cluster library spec: http://zigbee.org/?wpdmdl=2177
  • Active endpoint is defined by application and is not related to Zigbee spec. You can choose your own endpoints between 1 to 240. I don't remember Profile ID is defined by which Zigbee spec but you can find some information at www.eetimes.com/document.asp
  • Hi Yikai,

    here i have included part of zigbee profile definition from

    As they have mentioned profile ids are manufacturer-specific profiles and public. So for my application which one should i use manufacturer-specific profiles or public? In public profile they have mentioned home automation profile id as 0x0104.

    1)Will profile id be same for all the sensor if i want to use home automation public profile? They have mentioned

    but when i used profile id as 0x0f01 then the coordinator was not receiving data althogh coordinator and end device were getting binded and end device was sending data also but when i used 0x0f10 then coordinator was receiving data.

    2)So can you please suggest which will be better to use for my application.

  • 1. If you use HA profile, all devices should use 0x0104 as profile ID. Otherwise, they cannot talk each other.
    2. Can you describe your application so I can suggest? However, I suppose you should use HA profile.
  • My application consists of one coordinator and 8 end devices(sensors like temperature,PIR etc). Communication will take place in between coordinator and end device and end device to coordinator and no communication in between end device to end device.
  • Hi Yikai,
    is it mandatory to keep end points of all the end devices with same value? What i am finding is if i use "0x02" as end point then devices communicate same way if i keep "0x0F10" as profile id then my devices communicate but if i change these values to any other value like 0x03 as end point and 0x0104,0x0105 or any other value then devices do not communicate. Can i keep same end points for all the end devices?
    thanks
  • If you design all coordinator, routers, and end devices, I suppose you don't have to keep it.
  • Hi Yikai,
    Can you please explain it as i couldn't get you.
    1)Do you mean to say that if i use coordinator,router and end device in my network then it will not be mandatory to keep same end points for all the devices but if i have coordinator and end point only then its mandatory to keep same end point for all the devices in the network?
    2)I just wanted to know if i keep same profile id(which i should keep same for all the devices i suppose in order to communicate),end point but different cluster ids(A/c ZCL spec) for different devices then there will be no clash in between devices. i doubt if keeping same end point for different devices result in interference in between devices.
    Thanks
  • 1. I mean if you program the whole application, Zigbee coordinator, router, and end device, you can fix endpoint and don't have to keep it in your device list.
    2. It won't result in interference in between devices to use same endpoint for different devices.
  • Hi Yikai,
    I have problem with storing end device information after device announce. If i know what are the end device i am going to have in my network then can i proceed like this?
    When device announce occurs i will check whether short address is already present in device list. If short address will already be present i will leave else i will store short address in an array based on their cluster id and use that array to get short address while sending data to the particular end device for unicast transmission.
    Is it necessary to go for end point request and response and simple descriptor request and response? For my application i need only short address for unicast transmission
    Thanks
  • I see no problem to do what you describe.
  • Hi Yikai,
    Two of my end devices are getting interfered with one another. When i switch device "A" ON and keep other device "B" OFF then "A" works fine similarly when i switch device "B" ON and keep other device "A" OFF then "B" works fine but problem arises when two of the devices are ON at the same time. Command sent to device "A" is received by "B" and not "A".
    Following are the definitions of different end device configuration
    //ENERGY METER DEVICE CONFIGURATION
    #define ENERGY_METER_PROFILE_ID 0x0F10
    #define ENERGY_METER_ENDPOINT_ID 0X02
    #define ENERGY_METER_CMD_ID 0x0001 //energy meter cluster id(device "A")

    //TEMPERATURE SENSOR DEVICE CONFIGURATION
    #define ENERGY_METER_PROFILE_ID 0x0F10
    #define TEMP_ENDPOINT_ID 0x02
    #define TEMPERATURE_SENSOR_CMD_ID 0x0004 //temperature sensor cluster id(device "B")

    //PIR SENSOR DEVICE CONFIGURATION
    #definePIR_SENSOR_PROFILE_ID 0x0F10
    #define PIR_SENSOR_ENDPOINT_ID 0x02
    #define PIR_SENSOR_CMD_ID 0x0005 //PIR sensor cluster id

    Are above parameters configured correctly? Do i need to keep different value for other parameter which can result in such interference?
    Can you please suggest where may be the problem?
  • Sorry typing mistake.
    //TEMPERATURE SENSOR DEVICE CONFIGURATION
    #define TEMPERATURE_SENSOR_PROFILE_ID 0x0F10
    #define TEMP_ENDPOINT_ID 0x02
    #define TEMPERATURE_SENSOR_CMD_ID 0x0004 //temperature sensor cluster id(device "B")
  • Basically, I have no idea about what you are doing.
  • I am sending data from hyper terminal to the device configured as coordinator. based on data received from hyper terminal i am sending command(A,B,C..) to the particular end device using switch case. For this I am cluster id and short address of the end device. coordinator is controlling whole end devices. When command is received by the end device it will match for command received and according to that it will reply back to the coordinator.
  • I think it will be difficult unless you get clear idea. i will try myself to troubleshoot this problem. I just want to know if any parameter is there like cluster id,end point etc which can cause such problem.
  • Just wondering why different device would receive the same command if you use unicast.
  • I think it may be due to my incorrect routine for storing short address in array after device announce and extracting that short address from array while sending data. If coordinator extracts wrong short address from array while sending data then this type of problem may arise i suppose. I need to focus on this.
  • Yes! Try to debug your device list first.