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.

How to run HA SampleLight example on CC2530 custom board

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

Hi

I'm a beginner in Zigbee development and I've been studying the protocol for couple of weeks but now I decided to take it to the next step. So I have bought a couple of very little and cheap CC2530 modules. It's a 15*24mm module without a PA. So I designed an expansion board with 4 LEDs and 2 Switches to evaluate Z-stack HA SampleLight and SampleSwitch examples (apparently they are equivalent to the Hello World program!) 

Now I have completely learned about IAR environment and its different workspaces (Coordinator, Router, EndDevice), Linker files, Zigbee settings in XCL files, Compile options, CC-Debugger and a couple more of related things. I also almost learned the structure of the projects (SampleLight and SampleSwitch in Z-Stack Home 1.2.2) and the program itself (things like registering stuff, Clusters, Attributes, Commands, events, OSAL, HAL, ...) 

After looking into SmartRF05EB schematic I tried to use the same pins for LEDs and switches in my expansion board (however SmartRF05EB schematic is a nightmare!). Now since I don't have CC2530 Development Kit (stuff like SmartRF05EB and CC2530EM) I feel like I'm doing something wrong. I programmed one module as Coordinator with SampleLight project and the other module as Router with SampleSwitch project. in Coordinator (SampleLight) what happens is that one LED turns on and another LED turns on too after few seconds and they both stay that way. In Router (SampleSwitch) the first LED blinks every 1 second. After I push both switches nothing happens. 

I know first a network should form by Coordinator. Seems like it does. I didn't change PANID in xcl file (default is 0xFFFF). And I know that these two modules should bind together to be able to talk to each other and I think this is where I'm doing something wrong and they're not connected (bind) together for some reason

Unfortunately I don't have a Sniffer so I'm not sure what is going on exactly. 

Could one of you guys kindly help me through this? If I could get this simple example to work I'm sure I'd have a better perspective over Zigbee concepts. 

  • 1. Since P0.1 has been implemented as GPI in hal_key.c, I would suggest you to use P0.1 as first button to trigger EZ-mode. You can change "if ( keys & HAL_KEY_SW_2 )" in zclxxx_HandleKeys to "if ( keys & HAL_KEY_SW_6 )"
    2. Using P0.1 as example, revise hal_key.c to use P0.0 as another button and mapped it to SW1.
    3. LED1 and LED4 is mapped to P1.0, LED2 is mapped to P1.1, and LED3 is mapped to P1.4 in CC2530DK. You can refer to hal_board_cfg.h.

    By the way, Packet Sniffer is a key tool when you study Z-Stack so I suggest you to buy a CC2531 USB dongle for this purpose.
  • Thank you.
    1) First I have some questions about EZ-mode. Glad that you brought it up!
    Does the role of one node being Coordinator and the other being Router/End Device change by using EZ-mode?
    Cause I just read in the Document that "EZ-mode binds (connects) two devices together for normal communication, whether the devices are currently on a ZigBee network or not!". How is that possible? What about PANIDs, NWKIDs, Channel Number and thing like that? (AFAIK these IDs are the basic things in a Zigbee based network)
    I mean I just programmed one module as SampleLight Coordinator and the other module as SampleSwitch Router and I checked that ZCL_EZMODE was enabled for both applications. Is that correct and enough ?

    2) Would you say that EZ-mode is a more simple and convenient way to bind two or more applications (nodes) together? I mean is it only suitable for simple cases like this in which someone has to install and bind nodes together (the installer guy) or it doesn't have any limitation and could be used for almost any application?

    3) How does EZ-mode do this practically? In my case is it like "push two switches (SW6 on each module) exactly at the same time" and they're good to go?

    4) I have already connected P0.1 to a switch in my board but it will connect P0.1 to GND when it's pressed (it's Active Low). I guess I have to change it somehow to Active High according to SmartRF05EB schematic in which joystick common pin is connected to VCC. Right?

    5) I didn't get one part. Correct me if I'm wrong. SW2 is one of joystick states and according to zclSampleLight_HandleKeys() is responsible for triggering EZ-mode. Since I don't have a joystick I'm gonna have to use a ready to use pin (P0.1) which is assigned to SW6 in hal_key.c and there again since I don't have joystick I have to assign SW1 to some pin (e.g. P1.3 in my board) to do the toggle part. Right?

    Sorry with all these question! But right now I'm sort of confused. I'm really looking forward to your answer. Thanks again
  • 1. 2. &3.To understand EZ-mode better, you can read chapter 7 EZ-MODE in Z-Stack Home Develop's Guide.pdf in Z-Stack Home Document folder. Personally, I don't think EZ-mode is simple for user to join device and binding related clusters. The in/out clusters have to match on two device so the whole EZ-mode process can be done successfully. I think this need installer has some domain knowledge.
    4. P0.1 as SW6 in hal_kay.c is implemented to capture falling edge which is active low.
    5. Yes, you can use P1.3 to implement another button.
  • Thank you.
    Well I changed HAL_KEY_SW_2 to HAL_KEY_SW_6 in both zclSampleSw_HandleKeys() and zclSampleLight_HandleKeys() functions. But the weird thing here is that when I turn both modules on they go to EZ-mode even though I haven't pressed SW6 (that means P0.1 is not connected to GND). While you said P0.1 is Active Low.
    In fact when I press and hold SW6 and then I turn the modules on they wont join together and one LED keeps flashing. But when I leave P0.1 alone and turn them on they are connected together pretty much fast and after that pressing SW6 (connecting P0.1 to GND) doesn't make any difference.

    My other problem is that I don't know how to use P1.3 as SW1 to do the toggle. I saw SW6 in hal_key.c but I couldn't figure out which functions to change to use P1.3 as SW1. 

    I don't know why they made Z-stack and specially HAL drivers so weird and kind of complicated!

  • Try to set breakpoint in both zclSampleSw_HandleKeys() and zclSampleLight_HandleKeys() and check if it would hit the breakpoints when power-on. To change P1.3 as SW1, you have to revise the following defines to use P1.3

    /* SW_6 is at P0.1 */
    #define HAL_KEY_SW_6_PORT P0
    #define HAL_KEY_SW_6_BIT BV(1)
    #define HAL_KEY_SW_6_SEL P0SEL
    #define HAL_KEY_SW_6_DIR P0DIR

    /* edge interrupt */
    #define HAL_KEY_SW_6_EDGEBIT BV(0)
    #define HAL_KEY_SW_6_EDGE HAL_KEY_FALLING_EDGE


    /* SW_6 interrupts */
    #define HAL_KEY_SW_6_IEN IEN1 /* CPU interrupt mask register */
    #define HAL_KEY_SW_6_IENBIT BV(5) /* Mask bit for all of Port_0 */
    #define HAL_KEY_SW_6_ICTL P0IEN /* Port Interrupt Control register */
    #define HAL_KEY_SW_6_ICTLBIT BV(1) /* P0IEN - P0.1 enable/disable bit */
    #define HAL_KEY_SW_6_PXIFG P0IFG /* Interrupt flag at source */
  • Yes I tried to debug and put a breakpoint inside of "if ( keys & HAL_KEY_SW_6 )" and turns out that it does hit the breakpoints once after powering them on.
    Anyway I forgot to say that even before mapping anything to SW1 after reaching the zclSampleLight_HandleKeys() function the program does enter into the first condition (the condition responsible for toggle command):
    if ( keys & HAL_KEY_SW_1 )
    {
    giLightScreenMode = LIGHT_MAINMODE;

    // toggle local light immediately
    zclSampleLight_OnOff = zclSampleLight_OnOff ? LIGHT_OFF : LIGHT_ON;
    }
    Actually it happens all the time and LED1 keeps flashing all the time. While AFAIK HAL_KEY_SW_1 is not connected to anything yet. Why does it keep doing that? Isn't that suppose to toggle the LED after receiving toggle command from switch module?

    By the way I still haven't figured out the way reading keys works. Is it by polling or interrupting? Could you please explain this more?

  • SW1, SW2, SW3, and SW4 are not used by your application so you can remove them all from your hal_key.c to avoid those unsed IO to interfere them. By the way, key event implementation in Z-Stack is interrupt.

  • I'm having another problem with this example. I programmed one module as Sample Light ZC and another one as Sample Switch ZED.
    But I was expecting that ZED goes to sleep mode and doesn't draw much current to be battery powered but it does and also one LED is keep flashing even though I defined POWER_SAVING and NWK_AUTO_POLL and not defined LCD_SUPPORTED according to swra292.pdf document.
    After joining the network the average current is 6mA and doesn't strike me as power saving!
    What else should I do?
    Plus is there an option to make the ZED only transmitter so it doesn't turn on RX or poll on RX ever? (because that's what I need and it's not supposed to receive anything only sends when a key is pressed)
  • 1. Comment out HalLedEnterSleep() in hal_sleep.c to make LED not keep flashing.
    2. You can set POLL_RATE to 0 so end device won't do polling.
  • Thanks
    Two more questions:
    1-Now LED3 does not flash anymore but after joining to the network it's always in on state. Where does this come from? I think it shows that device is joined or something.

    2- Now I'm using polling method to find out which key is pressed instead of interrupt. Does this mean the device never enters into sleep mode?

    Am I supposed to use interrupt for a battery powered application? Because it is still drawing much current.

    And I just added this:
    3- What are EndDeviceEB - OTAClient and RouterEB - OTAClient in SampleSwitch project workspace in IAR?

  • 1. Can you specify which example you use as device and see LED3 always on?
    2. How do you use polling method? When you measure power consumption, do you remove debugger cable?
    3. These two OATClient examples are for OTA dongle+ OTA server to do OTA. You can refer to Z-Stack OTA Upgrade User's Guide.pdf in document folder.
  • 1- Sample Switch example. I just saw in ZDApp.c in ZDO_JoinConfirmCB() function there is HalLedSet(HAL_LED_3,HAL_LED_MODE_ON) and apparently it turns on LED3 after joining a network successfully.
    2- Simply by commenting out "#define ISR_KEYINTERRUPT" . After this stack is using polling method and each 100ms it checks for a key press. Yes I removed the debugger cable.
    Would you confirm that in polling method SoC is not in a sleep mode anymore?
  • 1. I think you can remove HalLedSet(HAL_LED_3,HAL_LED_MODE_ON) in ZDO_JoinConfirmCB to avoid LED3 get turned on.
    2. The device still goes to sleep mode after you comment out "#define ISR_KEYINTERRUPT". It just create a periodic event to check key pressed.
  • Thank you
    Anyway to make sure that the device consumes less current I defined ISR_KEYINTERRUPT and now I'm reading key presses using external interrupts. But still after joining to the network it is drawing too much current. About 5mA in normal mode (not sending anything) . Even though I'm not turning on any LEDs anymore.
    What is the problem?
    Now I only have a CC2530 module, a LDO regulator and couple of capacitors on my board. I don't know why their consuming this much current.
    Could it be because of other peripherals? I guess some of them are enabled by default. Like UART.
    Should I undefine HAL_UART and other unnecessary HALs to save more power? Is there any other HAL that is enabled by default other that UART?
    I can't think of anything else right know. As far as I know a ZED should consume about 1uA when it's not sending so that battery could live for a long time.
  • It sounds that your unused IOs have current leakages. How do you connect your CC2530 unused pins?
  • Unused pins are unused! They're not connected to anywhere. I just have 2 keys, 3 LEDs, a debugger connector (which obviously doesn't draw current when it's not connected!) and a LDO in input. That's all.
    Are you sure it's not something software related?
    I don't know maybe I need to disable something like I mentioned before. Cause I have the minimal hardware here.
  • Try to set unused pin to tri-state.
  • How can I do that?
  • You can set registers P0INP, P1INP, and P2INP. Please refer to CC2530 user guide at www.ti.com/.../swru191.
  • Well after playing around and burning my hand I finally figured what the real problem was. It was that stupid LDO. I thought before with myself that it's probably not a great LDO from IQ point of view, so what? it doesn't matter that much. But it turns out it actually did matter!
    When I read its datasheet I saw its IQ is 5mA!!
    So I removed it and tried to power the module directly from power supply and its sleep current reduced from 6mA to 70uA. Then I figured to disable some peripherals and yep, apparently its sleep current is 0.5uA now!
    Good experience, right?
  • It is good to know you get low power consumption now.