Thursday, September 8, 2016

How to use two UART ports in CC2530 Z-Stack

The following steps show how to use two UART ports in CC2530 Z-Stack

1. Define HAL_UART=TRUE, HAL_UART_ISR=1, and HAL_UART_DMA=2 in compile options.
2. Initialize and use UART0 (P0_2 as RX/P0_3 as TX)  as the followings:

void initUart0(halUARTCBack_t pf)
{
  halUARTCfg_t uartConfig;
  uartConfig.configured           = TRUE;
  uartConfig.baudRate             = HAL_UART_BR_115200;
  uartConfig.flowControl          = FALSE;
  uartConfig.flowControlThreshold = 48;
  uartConfig.rx.maxBufSize        = 128;
  uartConfig.tx.maxBufSize        = 128;
  uartConfig.idleTimeout          = 6; 
  uartConfig.intEnable            = TRUE;            
  uartConfig.callBackFunc         = pf;
  HalUARTOpen (HAL_UART_PORT_0, &uartConfig);
}

void uart0RxCb( uint8 port, uint8 event )
{
  uint8  ch;
  while (Hal_UART_RxBufLen(port))
  {
    // Read one byte from UART to ch
    HalUARTRead (port, &ch, 1);
  }
}

initUart0(uart0RxCb);

//Output "UART0 output test" to P0.3
HalUARTWrite( HAL_UART_PORT_0, "UART0 output test", (byte)osal_strlen("UART0 output test"));

3. Initialize and use UART1 (P1_6 as TX/P1_7 as RX) as the followings:

void initUart1(halUARTCBack_t pf)
{
  halUARTCfg_t uartConfig;
  uartConfig.configured           = TRUE;
  uartConfig.baudRate             = HAL_UART_BR_115200;
  uartConfig.flowControl          = FALSE;
  uartConfig.flowControlThreshold = 48;
  uartConfig.rx.maxBufSize        = 128;
  uartConfig.tx.maxBufSize        = 128;
  uartConfig.idleTimeout          = 6; 
  uartConfig.intEnable            = TRUE;            
  uartConfig.callBackFunc         = pf;
  HalUARTOpen (HAL_UART_PORT_1, &uartConfig);
}

void uart1RxCb( uint8 port, uint8 event )
{
  uint8  ch;
  while (Hal_UART_RxBufLen(port))
  {
    // Read one byte from UART to ch
    HalUARTRead (port, &ch, 1);
  }
}

initUart1(uart0RxCb);

//Output "UART1 output test" to P1.6
HalUARTWrite( HAL_UART_PORT_1, "UART1 output test", (byte)osal_strlen("UART1 output test"));

8 comments:

  1. Thank for your page. But I got a error when add line "HAL_UART=TRUE" in hal_board_cfg.h
    Error[e16]: Segment XDATA_Z (size: 0x1d0e align: 0) is too long for segment definition. At least 0x10f more bytes needed. The problem occurred while processing the segment placement command "-Z(XDATA)XDATA_Z,XDATA_I=_XDATA_START-_XDATA_END", where at the moment of placement the available memory ranges were "XDATA:301-1eff"
    Reserved ranges relevant to this placement:
    XDATA:1-300 XSTACK
    XDATA:301-1eff XDATA_Z
    BIT:0-7 BREG
    BIT:80-87 SFR_AN
    BIT:90-97 SFR_AN
    BIT:a0-af SFR_AN
    BIT:b8-c7 SFR_AN
    BIT:e8-ef SFR_AN
    Error while running Linker



    ReplyDelete
    Replies
    1. Can you tell me how are you resolved this problem ?

      Delete
    2. This comment has been removed by the author.

      Delete
    3. You can refer to http://processors.wiki.ti.com/index.php/Optimizing_Flash_and_RAM_Usage_of_Z-Stack_for_CC2530 to reduce ram and flash usage to make it.

      Delete
    4. Thank you, Now I can fix it.
      I change HAL_UART_DMA_RX_MAX=128 and XDATA (General Options > Stack/Heap > Stack Sizes > XDATA) = 200.
      It works

      Delete
  2. yes, i have same problem, z-stack 3.0

    ReplyDelete
    Replies
    1. You can refer to http://processors.wiki.ti.com/index.php/Optimizing_Flash_and_RAM_Usage_of_Z-Stack_for_CC2530 to reduce ram and flash usage to make it.

      Delete