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.

Send command through Serial com to CC2531

Other Parts Discussed in Thread: CC2531, Z-STACK, CC2531EMK

Hi everyone,

i'm working on a project, and i need to send command through Serial com to my CC2531 Zigbee Dongle, using Java.

there is someone who ever try that with java code? i search for code examples but i don't found anything about sending command with java through Serial com.

at the moment, i can only detect my CC2531 with my code using rxtx api, but i want to know how to send data or commands !

can anyone help me ?

thanks.

  • Check if your CC2531 dongle supports ZNP command. If yes, you can communicate by it.

  • yes, my dongle support the ZNP command, but i don't know how with Java, i can send the ZNP command ?

    i need an simple exemple of code. for exemple to send a SYS-RESET_REQ, ... this is my real question. 

  • To send SYS_RESET_REQ, you can write the following 6 bytes into UART or SPI.

    0xFE     0x01      0x41     0x00    0x00    0x40

    SOF  LENGTH   Cmd0   Cmd1   Type    FCS

  • this is the part of code that i use for sending the data.

     BufferedReader is = null;  // for demo purposes only. A stream would be more typical.
     PrintStream    os = null;

                    os = new PrintStream(port.getOutputStream(), true);

    // here i send the data
            
                    os.print(new byte[] {(byte) 0xFE, (byte) 0x01, (byte) 0x41, (byte) 0x00, (byte) 0x00, (byte) 0x40});
                    
            
                    
                    BufferedReader portReader =
                            new BufferedReader(new InputStreamReader(port.getInputStream()));

                        
                            String line = portReader.readLine();
                       
     

    but when i want to read data input, there is no response and the string line don't return anything.

  • I suggest you using scope to check if the HW signal is correct.

  • The signal is correct.

    I manage to send the sysping command and i had a callback response.

    but i didn't really get it, i want to know how can i calculate the FCS field to send with the packet ?

    for exemple with the sysping command the fcs is 20 but for exemple if i want to run a the sys_get_time command, what FCS do i have to do ? because i try to run it with the 20 value, but i had no callback response.

    but when i make the value to 30, it work, and i did'nt really understand why ?

    for the SYS_GET_TIME in run the following values and it work.

    buf = new byte[] {(byte) 0xFE, (byte) 0x00, (byte) 0x21, (byte) 0x11, (byte) 0x30};

                                              SOF            LEN          CMD0         CMD1         FCS

    So the Question is how to calculate the FCS field ?

  • I think i undestand, the fcs command is the result of a XOR from the LEN fields to the latest field before FCS.

  • Yes, it is described in section 2.1.1  General Serial Packet of Z-Stack Monitor and Test API.pdf.

    FCS(Frame Check Sequence): This is a one bytefield that is used to ensure packet
    integrity. This field is computed as an XOR of all the bytes in the message starting with
    LEN field and through the last byte of data. The receiver XORs all the received data
    bytes as indicated above and then XORs the received FCS field. If the sum is not equal to
    zero, the received packet is in error.

  • Adam, Yikai,

        The ZStack-Lighting Host Interfaces uses RPC (MT_APP) messages, we have some C examples of sending commands to the CC2531EMK on this wiki which may be useful: http://processors.wiki.ti.com/index.php/ZStack-Lighting-1.0.1_Host_Interface_C_Examples

    Regards, TC.

  • Thanks TopCat,

    sure it will be usefull !

    Best Regards, ZA.

  • i have a last question.

    if i want to toggle on/off my ZPLUG device, i need to use the AF_DATA_REQUEST command.

    the short address of my device is : 0xE71A.

    so i guess that i need to run the following values ==> 

    0xFE,  0x13,    0x24,     0x01,       0xE7, 0x1A,             0x01,                            0x0A,                  0x06,                0x00,             0x00,            0x00,        0x03,      0x01, 0x01, 0x02,     0xC6

     SOF,  LEN,   CMD0,   CMD1,      DESTADDR,  DESTENDPOINT  , SRCENDPOINT,   CLUSTERID,      TRANSID,   OPTIONS,    RADIUS,    LEN,                 DATA,         ,   FCS

    Do i have wrong ? because the command don't success ?

  • Try to switch endian of your short address to 0x1A 0XE7. Another possible problem might be your source end point and destination end point. Are you sure that the end point of your coordinator is 0x0a and the end point of ZPLUG device is 0x01?

  • Hi Chen,

    yes i'm sure that the endpoint of my coordinator is is 0x0a and the end point of ZPLUG is 0x01, because i tried the same values and i send the command using ZTOOL and it work !

    I will try to swich the values of the short address as you said. i will feedback later ! thanks :)

    Zerhouni Adam

  • i switch the values but it didn't work... do you have any other idea ?

  • Why does the len byte after SOF is 0x13? I think it should be 0x10, shouldn't it?

  • because this is the number of bytes in the packet, why do you think it should be 0x10 ? ( i will try )

  • Hi Zerhouni,

    I am sorry that the correct length is 13 in decimal and 0x0D in hex. So you use 0x13 as length byte is incorrect. You mixed up decimal and hex value. I think the correct command should be like:

    0xFE, 0x0D,0x24,0x01,0xE7,0x1A,0x01,0x0A,0x06,0x00,0x00,0x00,0x03,0x01,0x01,0x02,0xD9

  • Oh my god the rookie mistake lol.

    thanks for the notice, but anyway, i've corrected the error as you said, but it still doesn't work, i also recalculate the FCS, and i found that FCS = D2 not D9, but even with the two, the command still not working...

    so i think that i will search a sniffer to sniff the packet send by ZTOOL when i launch the AF_DATA_REQUEST so that i see the data sent.

    Thanks Chen

    Z.A

  • Hi Chen,

    i finally solve my problem.

    In fact, you had right, the FCS is D9, and alors i had to switch between the bytes of the short address as you said, and also i had another problem. i forgot that the field Cluster ID is in 2 byte not 1yte.

    so the final command which work is :

    FE, 0D, 24, 01, 1A, E7,01, 0A, 06, 00, 00, 00, 00, 03, 01, 01, 02, D9

    Thanks a lot for the help Chen!

    Best Regards.

  • I'm Back to you Chen for another question.

    I know that AF_DATA_REQUEST is used to send specific command to Devices such as SWITCH ON/OFF, but what i don't know is how have you found what are the lenght of data that we have to use (3 for Switch on/off) and what data to send in every Bytes ?

    And also for simple mettering for exemple ? can i use the AF_DATA_REQUEST to get the electrical consumation (and how : lenght of data and data to send?) or do i have to use the ZDO_POWER_DESC_REQ ?

    Best Regards