微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI Zigbee设计交流 > zstack使用双串口的问题

zstack使用双串口的问题

时间:10-02 整理:3721RD 点击:

我的项目中使用了UART0的P0口(ZAPP_P1)作为其中一个用途,现在我需要同时使用UART1的P1口(ZTOOL_P2)作为debug的串口,即可以和PC通信的打印口,我按照网络上的方法把UART0设置成DMA方式,UART1设置成ISR方式,修改代码如下:

#if HAL_UART
#ifndef HAL_UART_DMA
#if HAL_DMA
#if (defined ZAPP_P1) || (defined ZTOOL_P1)
#define HAL_UART_DMA 1
#else
#define HAL_UART_DMA 2
#endif
#else
#define HAL_UART_DMA 0
#endif
#endif

#ifndef HAL_UART_ISR
#if (defined ZAPP_P2) || (defined ZTOOL_P2)
#define HAL_UART_ISR 2

#elif (defined ZAPP_P1) || (defined ZTOOL_P1)
#define HAL_UART_ISR 1
#else
#define HAL_UART_ISR 1
#endif
#endif

IAR的option中有ZAPP_P1和ZTOOL_P2选项,我在把两个串口初始化完成后调用HalUARTWrite(HAL_UART_PORT_1, "hello", 5);不成功,PC端没有打印出“hello”,串口初始化代码如下:

void MT_UartInit ()
{
halUARTCfg_t uartConfig;

/* Initialize APP ID */
App_TaskID = 0;

/* UART Configuration */
uartConfig.configured = TRUE;
uartConfig.baudRate = MT_UART_DEFAULT_BAUDRATE;
uartConfig.flowControl = MT_UART_DEFAULT_OVERFLOW;
uartConfig.flowControlThreshold = MT_UART_DEFAULT_THRESHOLD;
uartConfig.rx.maxBufSize = MT_UART_DEFAULT_MAX_RX_BUFF;
uartConfig.tx.maxBufSize = MT_UART_DEFAULT_MAX_TX_BUFF;
uartConfig.idleTimeout = MT_UART_DEFAULT_IDLE_TIMEOUT;
uartConfig.intEnable = TRUE;
uartConfig.callBackFunc = MT_UartProcessZAppData;

/* Start UART */
HalUARTOpen (ZAPP_PORT, &uartConfig);

/* Initialize for ZApp */
#if defined (ZAPP_P1) || defined (ZAPP_P2)
/* Default max bytes that ZAPP can take */
MT_UartMaxZAppBufLen = 1;
MT_UartZAppRxStatus = MT_UART_ZAPP_RX_READY;
#endif


/* UART1 Configuration */
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_9600;
uartConfig.flowControl = MT_UART_DEFAULT_OVERFLOW;
uartConfig.flowControlThreshold = MT_UART_DEFAULT_THRESHOLD;
uartConfig.rx.maxBufSize = MT_UART_DEFAULT_MAX_RX_BUFF;
uartConfig.tx.maxBufSize = MT_UART_DEFAULT_MAX_TX_BUFF;
uartConfig.idleTimeout = MT_UART_DEFAULT_IDLE_TIMEOUT;
uartConfig.intEnable = TRUE;
uartConfig.callBackFunc = MT_UartProcessZToolData;
HalUARTOpen (ZTOOL_PORT, &uartConfig);

}

请问是怎么回事啊?

您可以参考这个帖子

https://e2e.ti.com/support/wireless_connectivity/zigbee_6lowpan_802-15-4_mac/f/158/t/169089

void initUart(halUARTCBack_t pf)
{
  halUARTCfg_t uartConfig;
  uartConfig.configured           = TRUE;
  uartConfig.baudRate             = HAL_UART_BR_19200;
  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);
}

And, the followings are the source code that use to initialized UART1 (P1_6/P1_7)

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);
}

I don't do anything special. Just wondering that is it possible that your TX/RX is revered. Do you want to change your HW from P0_2(RX)/P0_3(TX)  to P0_2(TX) and P0_3(RX)?

and change the Compile options ->C/C++ Compiler-> Preprocessor and Copy these lines in it.

HAL_UART=TRUE
HAL_UART_ISR=1
HAL_UART_DMA=2

Two uarts will start working

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top