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.

z-stack UART cc2530

Other Parts Discussed in Thread: Z-STACK, CC2530EM

Hello,

I use z-stack home automation, i need to use UART 1 on pins P1_6,  P1_7. How can I do it? 

 My code is follow:

HalUARTInit
 halUARTCfg_t uartConfig;
 uartConfig.configured = TRUE;
 uartConfig.baudRate = HAL_UART_BR_115200; //HAL_UART_BR_1M;
 uartConfig.flowControl = HAL_UART_FLOW_OFF;
 uartConfig.flowControlThreshold = 48;
 uartConfig.rx.maxBufSize = 128; //max if DMA gets enabled, don't think it is, but just in case
 uartConfig.tx.maxBufSize = 128;
 uartConfig.idleTimeout = 6;
 uartConfig.intEnable = TRUE;
 uartConfig.callBackFunc = NULL;

HalUARTOpen (HAL_UART_PORT_1, &uartConfig);

Printf ("hello world \r\n");

but it doesn't work, what should I do ? what is the right procedure sequence? 

Thank you

  • I just get in terminal a follow message ->   <0><0><0><0>

    It is look like wrong speed, but i don't know  exactly

  • You use 115200 as baud rate in UART open. Do you set the same 115200 baud rate in the terminal?

  • Another question about flow control, you disable it in UART open. Do you choode none of flow control in your terminal?

  • when I use this configure in Z-Stack 2.4.0 I have no problem - everything works fine (I redefined putchar of stdio.h and used DLIB in Project Options instead of CLIB)

    but when I use Z-Stack Home Automation UART sent crashed messages. I use CLIB because when i choose DLIB there is some error of linking.  

    What should i do? 

  • I've done it, you were right  about flowcontrol. I download another terminal and turned off flowcontrol , now it is works. Thank you very much!

    following code works:

    unsigned char str[]="Hello everybody";
    halUARTCfg_t uartConfig;
    uartConfig.configured = TRUE; // 2x30 don't care - see uart driver.
    uartConfig.baudRate = HAL_UART_BR_115200;
    uartConfig.flowControl = TRUE;
    uartConfig.flowControlThreshold = 48; // 2x30 don't care - see uart driver.
    uartConfig.rx.maxBufSize = 128; // 2x30 don't care - see uart driver.
    uartConfig.tx.maxBufSize = 128; // 2x30 don't care - see uart driver.
    uartConfig.idleTimeout = 6; // 2x30 don't care - see uart driver.
    uartConfig.intEnable = TRUE; // 2x30 don't care - see uart driver.
    uartConfig.callBackFunc = NULL;
    HalUARTOpen (HAL_UART_PORT_1, &uartConfig);
    HalUARTWrite(HAL_UART_PORT_1, str, 15);

    preprocessor:

    FEATURE_GREEN_POWER
    SECURE=1
    TC_LINKKEY_JOIN
    NV_INIT
    xNV_RESTORE
    xHOLD_AUTO_START
    ZTOOL_P2
    MT_TASK
    MT_APP_FUNC
    MT_SYS_FUNC
    MT_ZDO_FUNC
    ZCL_READ
    ZCL_WRITE
    ZCL_REPORT
    ZCL_EZMODE
    ZCL_BASIC
    ZCL_IDENTIFY
    ZCL_ON_OFF
    ZCL_SCENES
    ZCL_GROUPS
    xZCL_LEVEL_CTRL
    HAL_LCD=FALSE
    HAL_UART=TRUE

    hal_board_cfg.h

    /* Set to TRUE enable UART usage, FALSE disable it */
    #ifndef HAL_UART
    #if (defined ZAPP_P1) || (defined ZAPP_P2) || (defined ZTOOL_P1) || (defined ZTOOL_P2)
    #define HAL_UART TRUE
    #else
    #define HAL_UART TRUE
    #endif
    #endif

  • I am having trouble with incorporating UART in Home Automation demo examples. I want to connect a separate microcontroller to a CC2530EM SoC via UART.

    1. How can I add UART code in '........._event_loop', say in the 'zclSampleSw_event_loop()' in the SampleSwitch? Is it necessary to add the code in the event loop?

    2. If not then how can I receive UART data in the CC2530SoC? How and where to incorporate the code other than the event loop?


    Thanks in advance.

  • When you init UART by the following code, you should assign UART RX callback function to receive UART incoming characters.

    HalUARTInit
     halUARTCfg_t uartConfig;
     uartConfig.configured = TRUE;
     uartConfig.baudRate = HAL_UART_BR_115200; //HAL_UART_BR_1M;
     uartConfig.flowControl = HAL_UART_FLOW_OFF;
     uartConfig.flowControlThreshold = 48;
     uartConfig.rx.maxBufSize = 128; //max if DMA gets enabled, don't think it is, but just in case
     uartConfig.tx.maxBufSize = 128;
     uartConfig.idleTimeout = 6;
     uartConfig.intEnable = TRUE;
     uartConfig.callBackFunc = UART RX callback;

    HalUARTOpen (HAL_UART_PORT_1, &uartConfig);

  • Thanks a lot, Yikai Chen.I am sorry to bother you again. I far as I understand, the following event loop is the main loop that runs continuously. So from where do I modify and how to get the message? Will there be any SYS_EVENT_MSG which I would use in the event loop? If so, what is the header?  And how do I get the UART incoming message?

    uint16 zclSampleSw_event_loop( uint8 task_id, uint16 events )
    {
      afIncomingMSGPacket_t *MSGpkt;
      (void)task_id;  // Intentionally unreferenced parameter

      if ( events & SYS_EVENT_MSG )
      {
        while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclSampleSw_TaskID )) )
        {
          switch ( MSGpkt->hdr.event )
          {
    #ifdef ZCL_EZMODE
            case ZDO_CB_MSG:
              zclSampleSw_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
              break;
    #endif
            case ZCL_INCOMING_MSG:
              // Incoming ZCL Foundation command/response messages
              zclSampleSw_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
              break;

            case KEY_CHANGE:
              zclSampleSw_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
              break;

            case ZDO_STATE_CHANGE:
              zclSampleSw_NwkState = (devStates_t)(MSGpkt->hdr.status);

              // now on the network
              if ( (zclSampleSw_NwkState == DEV_ZB_COORD) ||
                   (zclSampleSw_NwkState == DEV_ROUTER)   ||
                   (zclSampleSw_NwkState == DEV_END_DEVICE) )
              {
    #ifndef HOLD_AUTO_START
                giSwScreenMode = SW_MAINMODE;
                zclSampleSw_LcdDisplayUpdate();
    #endif
    #ifdef ZCL_EZMODE
                zcl_EZModeAction( EZMODE_ACTION_NETWORK_STARTED, NULL );
    #endif
              }
              break;

            default:
              break;
          }

          // Release the memory
          osal_msg_deallocate( (uint8 *)MSGpkt );
        }

        // return unprocessed events
        return (events ^ SYS_EVENT_MSG);
      }

      if ( events & SAMPLESW_IDENTIFY_TIMEOUT_EVT )
      {
        zclSampleSw_IdentifyTime = 10;
        zclSampleSw_ProcessIdentifyTimeChange();

        return ( events ^ SAMPLESW_IDENTIFY_TIMEOUT_EVT );
      }

      if ( events & SAMPLESW_MAIN_SCREEN_EVT )
      {
        giSwScreenMode = SW_MAINMODE;

        zclSampleSw_LcdDisplayUpdate();

    #ifdef LCD_SUPPORTED
        HalLcdWriteString( (char *)sClearLine, HAL_LCD_LINE_2 );
    #endif
        return ( events ^ SAMPLESW_MAIN_SCREEN_EVT );
      }

    #ifdef ZCL_EZMODE
      if ( events & SAMPLESW_EZMODE_NEXTSTATE_EVT )
      {
        zcl_EZModeAction ( EZMODE_ACTION_PROCESS, NULL );   // going on to next state
        return ( events ^ SAMPLESW_EZMODE_NEXTSTATE_EVT );
      }

      if ( events & SAMPLESW_EZMODE_TIMEOUT_EVT )
      {
        zcl_EZModeAction ( EZMODE_ACTION_TIMED_OUT, NULL ); // EZ-Mode timed out
        return ( events ^ SAMPLESW_EZMODE_TIMEOUT_EVT );
      }
    #endif // ZLC_EZMODE

      // Discard unknown events
      return 0;
    }

  • Hi M,

    1. You can put the UART init code in zcl_SampleSw_Init().

    halUARTCfg_t uartConfig;
     uartConfig.configured = TRUE;
     uartConfig.baudRate = HAL_UART_BR_115200; //HAL_UART_BR_1M;
     uartConfig.flowControl = HAL_UART_FLOW_OFF;
     uartConfig.flowControlThreshold = 48;
     uartConfig.rx.maxBufSize = 128; //max if DMA gets enabled, don't think it is, but just in case
     uartConfig.tx.maxBufSize = 128;
     uartConfig.idleTimeout = 6;
     uartConfig.intEnable = TRUE;
     uartConfig.callBackFunc = UartProcessData;

    HalUARTOpen (HAL_UART_PORT_1, &uartConfig);

    2. Add the following UART RX callback function into your zcl_SampleSw.c to receive UART characters.

    void UartProcessData ( uint8 port, uint8 event )
    {
      uint8  ch;
      uint8  bytesInRxBuffer;
     
      while (Hal_UART_RxBufLen(port))
      {
        HalUARTRead (port, &ch, 1);
      }
    }

  • Thanks again,YiKai Chen. In my setup, incoming data is not continuous. I need a method to read UART buffer only when there is incoming data in the serial port. That is like an interrupt. I am confused about one thing, whenever I call the 'UartProcessData(port, event)', won't it hang the program until there is an incoming message? And is 'uint8 event' the 'Task_id' of my End Point?


    Or am I completely wrong about the whole thing?

     

     

  • Thanks a lot YiKai Chen. It's working now.

  • where s this function zclSampleSw_NwkState used ???

  • Hi dhileep,

    It is a variable that show you device network state and you can search zclSampleSw_NwkState in zcl_samplesw.c to see how it works.

  • yes sir ... i checked the whole pgm but couldnt find it 

  • Hi dhileep,

    Which examples are you testing?

  • sample switch in coordinator node 

    sample light in sensor node

  • Hi Dhileep,

    I have tried to answer you at http://e2e.ti.com/support/wireless_connectivity/f/158/p/380198/1342904.aspx#1342904

  • yes sir .... sorry for bothering you ... bt i didnt get the intended results yet sir 

  • hi Chen ,

         how can i use the uart to send out the Variable value to PC?? 

        i mean how to use the sending function。now i can use it to send string ,but i don't know howto send variable value

  • To output variable value, you can use sprintf function like the followings:

    char str[8];

    int a =100;

    sprintf(str, "%d", a);

    HalUARTWrite(HAL_UART_PORT_0,  str, 8);

  • I'm trying to do the same task but I'm having some trouble

    I'm using the following code:

    unsigned char my_str[] = "Pranav and Saswat";

    HalUARTInit();
    halUARTCfg_t config_uart;
    config_uart.configured = TRUE;
    config_uart.baudRate = HAL_UART_BR_115200;
    config_uart.flowControl = TRUE;
    config_uart.flowControlThreshold =48;
    config_uart.rx.maxBufSize = 128;
    config_uart.tx.maxBufSize = 128;
    config_uart.idleTimeout = 6;
    config_uart.intEnable = TRUE;
    config_uart.callBackFunc = NULL;
    HalUARTOpen (HAL_UART_PORT_0, &config_uart);
    HalUARTWrite(HAL_UART_PORT_0, my_str, 17);

    Instead of simply displaying the required string, the following output is obtained on hyperterminal:

    "H€ZigBee Coord§þHPranav and Saswat"

    Could you please help me remove the unwanted part?

    Thanks,

    Pranav Pal Lekhi

  • Can you specify which Z-Stack version and example your are using?
  • Thanks for the quick reply
    I'm using Z-stack Home 1.2.2.42930
    I'm using the sample switch example
  • That message is generated by "debug_str( (uint8*)buf )" in API HalLcdWriteString(). You can disable it to not show this message.
  • Thank you, YK Chen,
    The message has disappeared now
  • You are welcome.