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.

  • You can try to trace into MT_ProcessEvent().
  • Thanks for your quick reply. I think i should learn DMA access before i proceed for tracing MT_ProcessEvent() & MT_UartProcessZToolData() functions as these functions use DMA at later stage(HalUARTWriteDMA() & HalUARTPollDMA() functions) which i am not familiar with. Will get back soon.
  • Thanks for your kind support. Now i am able to understand the flow sequence and able to transmit and receive data through uart.

    My device is not getting detected in z-tool application. What procedures i need to follow for this. I am using ZNP code with uart dma?
    Any web link or supporting document for this?
  • You say you are able to transmit and receive data through UART. Then, you should be able to connect it to Z-Tool without problem. Do you use correct baud rate?

  • Actually i had modified HalUARTReadDMA function as follows to return the read buffer from uart as a seperate function.

    static uint8* HalUARTReadDMA1(uint8 *buf, uint16 len)
    {
    uint16 cnt;

    for (cnt = 0; cnt < len; cnt++)
    {
    if (!HAL_UART_DMA_NEW_RX_BYTE(dmaCfg.rxHead))
    {
    break;
    }
    *buf++ = HAL_UART_DMA_GET_RX_BYTE(dmaCfg.rxHead);
    HAL_UART_DMA_CLR_RX_BYTE(dmaCfg.rxHead);
    #if HAL_UART_DMA_RX_MAX == 256
    (dmaCfg.rxHead)++;
    #else
    if (++(dmaCfg.rxHead) >= HAL_UART_DMA_RX_MAX)
    {
    dmaCfg.rxHead = 0;
    }
    #endif
    }
    PxOUT &= ~HAL_UART_Px_RTS; // Re-enable the flow on any read.
    return buf;
    }

    and i am calling it in znpEventloop function as follows.

    uint16 znpEventLoop(uint8 taskId, uint16 events)
    {
    osal_event_hdr_t *pMsg;
    uint8 *buf1,*buf2;

    buf2=HalUARTRead1(HAL_UART_PORT_0,buf1,4);
    HalLcd_HW_WaitUs1(40000); // 15 ms
    HalUARTWrite(HAL_UART_PORT_0,buf2,4);
    HalLcd_HW_WaitUs1(40000); // 15 ms
    .
    .
    .

    here buf2 will store the data sent through uart and it will be transmitted back to hyperterminal using HalUARTWrite() function. Thus i am able to transmit and receive data from uart. These i had done just to test basic transmission and reception.

    When i connect my device in z-tool application then it shows No device found.
  • I think your revised code act like loop back on UART and it might make Z-Tool confused. Why do you need to revise UART DMA in this way? If you intend to trace ZNP code, you can set break points and debug with IAR and CC Debugger.
  • I will try by removing those receiving and sending code. As i had mentioned i was just trying to check basic uart communication so i had added that code.

    Actually none of the sample projects available in z-stack is showing any communication in between coordinator and end device. Only home automation code is working fine and led is toggling with switch press. All other codes are having binding problem for my device. There is no binding in between coordinator and end device. So i am trying step by step. My basic requirement is to transmit data read from temperature sensor as in simple app project. I am struggling a lot in this. Please help.
    Thanks
  • Z-Stack 2.5.1a is obsolete. I would suggest you to test example in Z-Stack home 1.2.1.
  • I know that z-stack is obsolete and well proven by different world communities and its members and i have no issue at all. I had tried by making different changes like port configuration for key detection,interrupt routines etc in the sample projects based on my hardware and these may be reason for no communication.
    Meanwhile i will try with z-stack home 1.2.1. as you said and check for result.
    Thanks.
  • I had tried by removing those iterating uart read and write functions from znp event loop what i had mentioned in my previous posts. Then downloaded the code in my hardware and cheked it in z-tool application. Now also z-tool shows no devices found.

    Then i had downloaded z-stack home 1.2.1. as told by you and extracted the .exe file by installing it. When i tried to open the ide workbench file then it shows following error.

    Broken options were detected in the project file. A backup copy will be made. check log window for details

    and when i had compiled that file then it shows following error

    array is too large

    in static __no_init osalMemHdr_t theHeap[MAXMEMHEAP / OSALMEM_HDRSZ]; 

     & HAL_DMA_SET_DEST( ch, dmaCfg.rxBuf ); functions and other 20 places beside these.

    Other error i am getting is

    Error[Pe167]: argument of type "unsigned char *" is incompatible with parameter of type "unsigned char volatile __xdata C:\Users\qmaxsystems\Desktop\Z-Stack Home 1.2.1\Components\mac\low_level\srf04\mac_autopend.c 472

    in MAC_RADIO_SRC_MATCH_SET_EXTPENDEN( buf ); function and other 5-6 lines

    Totally 28 errors are found after compiling.
    Can you please advice me possible cause for these errors. I am using CC2530

    Thanks.

  • I had tried by removing those iterating uart read and write functions from znp event loop what i had mentioned in my previous posts. Then downloaded the code in my hardware and cheked it in z-tool application. Now also z-tool shows no devices found.

    Then i had downloaded z-stack home 1.2.1. as told by you and extracted the .exe file by installing it. When i tried to open the ide workbench file then it shows following error.

    Broken options were detected in the project file. A backup copy will be made. check log window for details

    and when i had compiled that file then it shows following error

    array is too large

    in static __no_init osalMemHdr_t theHeap[MAXMEMHEAP / OSALMEM_HDRSZ];

    & HAL_DMA_SET_DEST( ch, dmaCfg.rxBuf ); functions and other 20 places beside these.

    Other error i am getting is

    Error[Pe167]: argument of type "unsigned char *" is incompatible with parameter of type "unsigned char volatile __xdata C:\Users\qmaxsystems\Desktop\Z-Stack Home 1.2.1\Components\mac\low_level\srf04\mac_autopend.c 472

    in MAC_RADIO_SRC_MATCH_SET_EXTPENDEN( buf ); function and other 5-6 lines

    Totally 28 errors are found after compiling.
    Can you please advice me possible cause for these errors. I am using CC2530

    Thanks.
  • To build examples in Z-Stack Home 1.2.1, you have to install IAR workbench for 8051 version 8.20. Do you use this version?
  • Sorry for late reply. I am using IAR workbench for 8051 version 8.20.2.
  • To build Z-Stack Home 1.2.1, you should use IAR 8.30. Sorry for my typo.
  • Thanks for your reply. I will check by installing iar version 8.30.
    Can you please suggest me what things i need to keep in mind for getting device detected in z-tool like preprocessors that need to be included while compiling, port configuration and others. I mean to say what changes i need to make in the original sample code provided in z-stack based on my hardware. I do not have evaluation board for this and i am using my own cc2530 based hardware.
  • It is pretty straight forward. You just build and download to run ZNP project in Z-Stack Home 1.2.1

  • I have installed 8.30. its asking for licence renewal. if i get new licence for 8.30 will my trial licence for 8.20 be lost? I am worried if new licence for 8.30 affects other projects working with 8.20 version. Will older version programs run smoothly in 8.30 without making any effect?
  • Different Z-Stack uses different IAR version. I suggest you using correct version for each. This information is specified in release note of each Z-Stack.
  • Hi Yikai Chen

    Thanks for your reply.I have got licence for iar 8.30 and using Z-Stack Home 1.2.1. Even now my device is not getting deteceted in z-tool. I had checked by setting different baud rates. Then i had included following preprocessors

    ZTOOL_P1

    MT_TASK

    MT_ZDO_FUNC

    MT_APP_FUNC

    MT_SYS_FUNC

    MT_ZDO_CB_FUNC

    LCD_SUPPORTED=DEBUG in project->options->c/c++ compiler->preprocessor as mentioned in swra119 document(to add MT_TASK).

    While compiling i am getting error like

    Error[e27]: Entry "MT_TransportAlloc::?relay" in module MT_TASK ( C:\Users\qmaxsystems\Desktop\Z-Stack Home  

    1.2.1\Projects\zstack\ZNP\CC253x\CC2530-Debug\Obj\MT_TASK.r51 ) redefined in module znp_app ( C:\Users\

    qmaxsystems\Desktop\Z-Stack Home 1.2.1\Projects\zstack\ZNP\CC253x\CC2530-Debug\Obj\znp_app.r51 )

    Error while running Linker

    I can see that MT_TransportAlloc and MT_TransportSend functions are defined in both znp_app.c and MT_TASK.c files. Got confused which one to keep and which one to ignore or keep both. Please advice how to proceed.

    Thanks

  • I have no problem using ZNP project on CC2530EM+SmartRF05EB. Since you are using customized PCB, I suggest you to check if P0.2 (UART RX pin) and P0.3(UART TX pin) are connected correctly with level shifter to your PC COM port.

  • Hi Yikai,
    Finally i have made my device detected in z-tool application using znp. i had to make so many changes for this. Since znp doesn't uses binding methodology so i want to convert home automation code(sample switch & light) into znp so that it can be detected in z-tool. I had made changes similar to configurations present in znp application but its not detecting. Can you please suggest solution by which i can do this. My requirement is to send binding request and data through uart and then transmit through zigbee protocol. I am using z-stack Version 2.5.1a
    Thanks
  • You can define ZTOOL_P1 and othe MT_xXX in project option of SampleLight and SampleSwitch. Then, they can be controlled by ZTOOL using ZNP/MT commands. In this way, you can send binding command using UART.
  • Lots of thanks for your kind support. Now my Home automation code(sample switch and light) is getting detected in z-tool application. But i am getting one warning
    *** WARNING ***
    Expected Z-Stack version (2.6.2) does not match with actual Z-Stack version (2.5.1). Z-Tool may not work properly.
    Any solution for this?
  • Since you are using Z-Stack 2.5.1a, you should use Z-Tool in the same Z-Stack version. It seems that you use Z-Tool in Z-Stack Home 1.2.1 to connect to ZNP in Z-Stack 2.5.1a
  • Ya, you are correct. I had checked with z-tool application of the same Z-Stack 2.5.1a and now i am not getting any such warning. I am not using Z-Stack Home 1.2.1 as i am getting lots of errors what i had mentioned in my previous posts long back even if i am using iar 8.30 version.
  • Hi Yikai,
    Is there any procedure like storing in flash memory by which devices can retain binding table information even if it is unpowered.

    What i want is device should retain binding information even if it goes to off condition and send data with the same binding information and hence there should be no necessity to bind again and again when powered on for the next time. Unbinding should be done manually based on user wish when they want to remove particular device from network.
    Thanks
  • Continuation to my previous post..

    There are two modes of binding. One is self binding means when device will be powered on then it will send bind information on its own(without any key press for bind request). But with this configuration any new device(which is not a part of present network but has same configuration as device in present network) when comes in range of the present network will get binded and data will be transmitted to this new device also which is not my intention. Device should only communicate when it is intended.

    Other is sending binding request based on key press, but with this configuration every time device gets switched off we need to press switch for binding request.

    I want that device should bind only if switch is pressed but at the same time it should store binding information so that next time its powered on there is no need to press switch for binding and in this way unknown device will not be able to communicate but registered devices can. Can you please suggest any solution for this?
  • Continuation to my previous post..

    There are two modes of binding. One is self binding means when device will be powered on then it will send bind information on its own(without any key press for bind request). But with this configuration any new device(which is not a part of present network but has same configuration as device in present network) when comes in range of the present network will get binded and data will be transmitted to this new device also which is not my intention. Device should only communicate when it is intended.

    Other is sending binding request based on key press, but with this configuration every time device gets switched off we need to press switch for binding request.

    I want that device should bind only if switch is pressed but at the same time it should store binding information so that next time its powered on there is no need to press switch for binding and in this way unknown device will not be able to communicate but registered devices can. Can you please suggest any solution for this?
    Thanks
  • If you define NV_RESTORE in your project, the binding table would be stored even doing power recycle.
  • Hi Yikai,
    Thanks for your reply. I had tried by adding NV_RESTORE preprocessor in project options in home automation code(sample switch and light). What i found is led doesn't toggles with switch press when i use this preprocessor but led toggles when i remove it. I had tried by adding processor in both(switch and light) and individually(either of two) also but none of them worked. Am i missing anything?
  • I don't see any reason NV_RESTORE would cause this. There must be something wrong with your modification. Try to set breakpoints and debug it.
  • Hi Yikai,
    Thanks for your valuable support. Now the devices are storing binding information even after power off condition. I don't know reason why NV_RESTORE was causing that effect or it was due to something else. I had tried to debug but i was not able to set breakpoints as it was not accepting.

    Is there any way by which we can read the binding table information like which are the devices which are binded, their short address,source address,destination address etc. I could find some related functions in BindingTable.c files but these functions are not called in other files.
  • It is stored in BindingTable[]. You can read it directly.
  • Hi Yikai,
    if i am right then i should use
    static uint16 HalUARTReadDMA(uint8 *buf, uint16 len)
    function to read BindingTable[] which will store data in buf pointer. But for this i need to provide len as parameter which is not known how much it will be.
    Or is there any other way to read them?
    I want to know the status of devices which are connected to the network.
    Thanks
  • typedef struct
    {
    // No src address since the src is always the local device
    uint8 srcEP;
    uint8 dstGroupMode; // Destination address type; 0 - Normal address index, 1 - Group address
    uint16 dstIdx; // This field is used in both modes (group and non-group) to save NV and RAM space
    // dstGroupMode = 0 - Address Manager index
    // dstGroupMode = 1 - Group Address
    uint8 dstEP;
    uint8 numClusterIds;
    uint16 clusterIdList[MAX_BINDING_CLUSTER_IDS];
    // Don't use MAX_BINDING_CLUSTERS_ID when
    // using the clusterIdList field. Use
    // gMAX_BINDING_CLUSTER_IDS
    } BindingEntry_t;
    extern BindingEntry_t BindingTable[];
    According to above structure,BindingTable[] size should be [1+1+2+1+1+2*4=14] bytes. Will 14 be parameter for the len variable in static uint16 HalUARTReadDMA(uint8 *buf, uint16 len) function for reading BindingTable array when 1 device is binded?
  • Extremely sorry. static uint16 HalUARTReadDMA(uint8 *buf, uint16 len) function is for reading data sent through uart. Will check for function which will read the Bindingtable[].
  • If you want to get anything from binding table, you can use API in BindingTable.h. For example, you can use API GetBindingTableEntry() to get a pointer to the Nth valid binding table entry.
  • Hi Yikai,
    Below is code for printing "hello" when sensor sends battery report and "dear" when sensor sends temperature report every 5secs in simpleapp with simplecollector configured as coordinator and simplsensor configured as enddevice.

    if ( pData[0] == BATTERY_REPORT )
    {
    tmpLen = (uint8)osal_strlen( (char*)strBattery );
    pBuf = osal_memcpy( pBuf, strBattery, tmpLen );

    *pBuf++ = (sensorReading / 10 ) + '0'; // convent msb to ascii
    *pBuf++ = '.'; // decimal point ( battery reading is in units of 0.1 V
    *pBuf++ = (sensorReading % 10 ) + '0'; // convert lsb to ascii
    *pBuf++ = ' ';
    *pBuf++ = 'V';
    HalUARTWrite(HAL_UART_PORT_0,"hello",5);

    }
    else
    {
    tmpLen = (uint8)osal_strlen( (char*)strTemp );
    pBuf = osal_memcpy( pBuf, strTemp, tmpLen );

    *pBuf++ = (sensorReading / 10 ) + '0'; // convent msb to ascii
    *pBuf++ = (sensorReading % 10 ) + '0'; // convert lsb to ascii
    *pBuf++ = ' ';
    *pBuf++ = 'C';
    HalUARTWrite(HAL_UART_PORT_0,"dear",4);

    }
    and below is pattern i am getting through uart.
    h?e?ll?o?d?ea?r?h?el?l?o?d??e?a?r?........
    instead of hellodearhellodearhellodear.........

    I have tried by setting different baud rate like 9600,348400,115200 etc both in code
    at #define MT_UART_DEFAULT_BAUDRATE
    and same in hyperterminal also but same types of pattern results in all cases(junk characters coming with data). Where may be the problem?
    Thanks
  • Maybe these "?" are caused by other MT related function. Try to disable all of MT_XXX related define in your project and test again.
  • Hi Yikai,
    thanks a lot for the support i have got from you till yet. So far i am able to interface temperature sensor with CC2530 and transmit data from sensor to coordinator(one to one communication).
    I had made following changes in the code
    //UxUCR = UCR_FLOW | UCR_STOP;
    UxUCR &= ~UCR_FLOW;
    UxUCR |= UCR_STOP;
    in static void HalUARTOpenDMA(halUARTCfg_t *config) function in _hal_uart_dma.c file and "?" symbols coming along with data were eliminated.
    Now i want to bind multiple devices and transmit data among them. Can you please guide me what extra things need to be added in the existing code for one to many communication. I am using simple apps(simple sensor and simple collector). Any supporting documents can also be helpful.
  • What do you mean one to many communication? Can you explain in details so I can give you suggestion?

  • Sorry. Actually by one to many, i meant to say multiple device communication.
    Following are the specifications that are required i my program
    1)Multiple(temperature,accelerometer,LPG etc) sensor device(end device) should send data to the single coordinator only when requested by the coordinator( by sending command).
    2)Requesting command is sent from hyperterminal to the coordinator using uart.
    I want to know whether i need to add command id for each devices and what else i need to add in existing code for one to one communication.
    Thanks.
  • 1. You can use ZCL read attribute command to do this since ZC would receive end node announcement and application can get active endpoints and its supported clusters/attributes.
    2. You can use MT command to do this. Please refer to Z-Stack Monitor and Test API.pdf in Z-Stack Document folder.
  • Actually by command i mean to say data sent from hyper terminal and not MT commands as described below.
    If 0x01 is sent from coordinator then temperature sensor should send data to the coordinator,
    if 0x02 is sent from coordinator then humidity sensor should send its data to the coordinator,
    if 0x03 is sent then light should toggle at the end device etc. Here 0x01,0x02,0x03 i referring to the commands.
    So each device should have seperate command id. For following application what changes i need to make? In my final application i am not going to use PC(hyper terminal) and hence i can't use z-tool. In place of PC, i will be sending commands from android apps(using android box) which will send command to CC2530 through uart. Based on this command received, ZC and ZED will be communicating.

    I know that i need to include device command ids in following in SimpleCollector.c file
    // List of output and input commands for Collector device
    const cId_t zb_InCmdList[NUM_IN_CMD_COLLECTOR] =
    {
    SENSOR_REPORT_CMD_ID
    }; and similar in the sensor side also.
    Other than this do i need to make other changes? In which function do i need to send these commands at coordinator side and in function will i receive these commands at the end device so that later i can send data to the coordinator.
  • You want to request data from ZC to any ZED. It means that you have to know all the short address, active endpoint, and simple description of ZEDs. Then, you can send read attribute command. According to my experience, the easiest way is to use MT command. Otherwise, you have to wrap all these stuff by yourself.
  • For that only i had asked how to get binding information like short address, active endpoint, simple description etc of ZEDs so that i can send commands from android apps. I cant use z-tool application in android app due to support problem.
    Any how I am not going to disturb any part of code but only want somehow to read data coming through uart at the coordinator side and read these commands at the sensor side.
  • Now i am able to send data from multiple end devices to the coordinator.

    You had told that for getting binding information, i need to use BindingEntry_t *GetBindingTableEntry( uint16 Nth ) function defined in BindingTable.c file. How can we know the parameter "Nth" for this function how much it will be when many devices are binded together in the network? I want to know which are the devices binded together so that i can send commands to the particular device based on their device information.
  • Is there any function to set an event when data is sent to the device through uart as an indication that device has received some data? Based on this event i want to read UxDBUF and transmit command from the coordinator.
  • You can use bindCapacity to the number of binding entries possible and used.
  • When you init UART, you have to register a RX callback, which would be called when device receives UART data.