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 Mini ZNP Kit - Bidirectional communication between Coordinator and end device

Other Parts Discussed in Thread: CC2530, Z-STACK

Hello,

I was working on CC2530 Mini ZNP Kit for an academic project; I could set up the kit & was able to set up basic communication using communication examples

My question is:

How do I have a basic communication from coordinator to the end device?

I see that in the examples that the basic communication is from end device to coordinator; where coordinator only do displayReceivedMessages();

Is there any way that coordinator can send data to the end device? 

my aim is to set up a bidirectional data transfer between the coordinator and end device?

Please help, I have no idea !

Thanks, Sharika

  • Hi,

    The coordinator's short address is always 0x0000. Use destinationShortAddress=0 when calling afSendData() (AF/ZDO interface) or sendData() (Simple API interface).

    Regards,

    Kristof

  • hello Kristof, Thank you for your reply

    I have communication from End device to Coordinator working smoothly !


    My final aim is a Bidirectional Communication between Coordinator & End Device

    Breaking down my task I tried to make the coordinator transmit and end device receive; & thinking later to make it bidirectional ? m i in the right way?

    -------------------------------------------------------------------------------------------------------------

    To make Coordinator transmit 1 byte data to End device

    --------------------------------------------------------------------------------------------------------------------------------------

    Coordinator Code

     while(1)
        {
            unsigned char testMessage[] = {0x0B};   
            afSendData(DEFAULT_ENDPOINT,0x0000, 0, TEST_CLUSTER, testMessage, 1);
        } 

    End Device Code

    while (1)
        {
            setLed(1);
            
             /* Now the network is running - continually poll for any received messages from the ZNP */
    #ifdef FIND_MAC_ADDRESS_OF_SENDER  //define this to print out sender's MAC address
       displayReceivedMessagesAndFindDevice();
    #else
       displayReceivedMessages();
    #endif  

            handleReturnValue();
            clearLeds();        
            HAL_SLEEP();
        }

    ************************

    HyperTerminal

    ------------------------------

    Basic Communications Example - END DEVICE - using AFZDO
    Accelerometer Registers: whoAmI = 53, revId = 10
    Calibrating VLO...
    VLO = 12422 Hz;  Done.
    Success
    Setting StartupOptions
    Success
    Reset the ZNP
    Success
    Setting Zigbee Device Type
    Success
    Registering Application
    Success
    Starting the Application
    Success
    Rx: 01 45 C0 06

    On Network! HhU¹‘¥¹Message 0 #################################################
    ################################################################################
    ###########################################################

  • Uh, Sorry..

    When you get a message from the End Device you can extract the short address in the following way: 

    unsigned int ansAddr = CONVERT_TO_INT(znpBuf[SRSP_HEADER_SIZE+4],znpBuf[SRSP_HEADER_SIZE+5]);

    Regards,

    Kristof

    Edit: The offsets in the znpBuf can be different, I use this code with UART communication, not SPI.

  • When I debug the code, at End Device = > SRDY_IS_HIGH is not going low(meaning no message is coming right?) so the code is locked up at the line while (SRDY_IS_HIGH()); & never go to pollAndDisplay(); to execute CONVERT_TO_INT(znpBuf[2], znpBuf[1]) == ZDO_STATE_CHANGE_IND
    but in the console I see a '#' keep coming...??

    ----------------------------------------------------------------------------------------------------------------------------------------

    void waitForDeviceState(unsigned char expectedState)
    {
        unsigned char state = 0xFF;
        while (state != expectedState)
        {
            while (SRDY_IS_HIGH());         
            pollAndDisplay();
            if (CONVERT_TO_INT(znpBuf[2], znpBuf[1]) == ZDO_STATE_CHANGE_IND)
                state = znpBuf[SRSP_PAYLOAD_START];
        }
    }

    /** Waits for SRDY to go low, indicating a message has arrived. Displays the msg to console. */
    void displayReceivedMessages()
    {
        while (1)
        {       
            while (SRDY_IS_HIGH());         
            pollAndDisplay();
        }
    }

  • When I debug the code, at End Device

    In displayReceivedMessages() the code is locked up at while (SRDY_IS_HIGH());   i.e. SRDY never goes low, indicating a message has arrived
    & never go to pollAndDisplay();

    but in the console I see a '#' keep coming...??

    ----------------------------------------------------------------------------------------------------------------------------------------

    void pollAndDisplay()
    {
            spiPoll();
            if (znpBuf[SRSP_LENGTH_FIELD] > 0)
            {
                printf("Rx: ");
                printHexBytes(znpBuf, (znpBuf[SRSP_LENGTH_FIELD] + SRSP_HEADER_SIZE));
                znpBuf[SRSP_LENGTH_FIELD] = 0;
            }
    }

    /** Waits for SRDY to go low, indicating a message has arrived. Displays the msg to console. */
    void displayReceivedMessages()
    {
        while (1)
        {       
            while (SRDY_IS_HIGH());         
            pollAndDisplay();
        }
    }

  • Hi,

    Try to use 0xFFFF as short address when sending messages from the Coordinator. 0xFFFF is the broadcast short address defined as ALL_DEVICES in znp_interface.h.

    Regards,

    Kristof

  • Thanks a lot Kristof

    Where do u get these information like 0xFFFF is broadcast short address ??
    Can you please share that guide to me? I am going through the code to understand things

    Thanks, Sharika

  • Ok, I forgot to mention the CC2530ZNP_interface_specification.pdf (TI literature number SWRA312) ...

    Regards,

    Kristof

  • Hi, 

    Also read the "Z-Stack Developer's Guide.pdf" (SWRA176)

    Regards,

    Kristof

  • Thanks kristof,

    Bidirectional communication works smoothly now using broadcast :

     afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0XFFFF, TEST_CLUSTER, testMessage, 6);

    Howevr I am unable to do a unicast in "basic_comms_coordinator_afzdo"

    Please let me know if you have any idea about unicast

    ~Sharika

     

  • I encounter the similar problem using sample code in "example_basic_comms_xxx_afzdo.c".

    I tried the solutions about broadcast from Coordinator, it works from coordinator to end device.

    However, if the coordinator receives information from end device to process first and then sends back. The end device never receives any signal from coordinator ( the SRDY_IS_HIGH() never go low )

    I have tried for both broadcast and specify destination short address, and they didn't work.

    Any idea about where the problem is ? Thanks.


    the simplified code is listed following:

    [Coordinator]------------------------------------------------

     while (1)

    {

      while (SRDY_IS_HIGH());  //Receive something here, it works well...

      pollAndDisplay();

      // do something ..

      afSendData(DEFAULT_ENDPOINT, DEFAULT_ENDPOINT, 0XFFFF, TEST_CLUSTER, data, 2);

      handleReturnValue();

    }

    [End device]------------------------------------------------

     while (1)

    {

      afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, data, 2);

      handleReturnValue();

      delayMs(500); //wait for coordinator

       while ( SRDY_IS_HIGH() );  //the SRDY_IS_HIGH() never go low here ...
       pollAndDisplay();

       //Do something ...

    }

  • I put a "delayMs(1000)" before calling afSendData() in Coordinator, and the bidirectional communication works !

  • Hey guys, I know it's been a while but I was wondering, where in the original sample code did you make the modifications? I have tried many different aproaches a to where to modify it but I keep getting "error -31" at the wait for message method.

    Thank you just for reading this!

  • Hi, I use "example_basic_comms_coordinator_afzdo" and "example_basic_comms_end_device_afzdo" for code modifications. All the modifications are made in the main function. Try to put a delay function after receiving a message before you send something via afSendData.

  • hi,Sharika Kumar

    pls send me a source code link of  Bidirectional Communication between Coordinator & End Device....

    pls u can send to my mail id also navorammu@gmail.com

     

    Thanks,