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.

How to configure UART1 in Z Stack GenericApp?

Other Parts Discussed in Thread: CC2530EM

Hello,


I'm using the CC2530EM attached to an SOC-BB and I want to configure UART1. TD and RD are accessed through Port 1 pins 6 and 7.

I need to read in a byte of data over UART1 on one SOC-BB (end-device), transmit this data over the air to another SOC-BB (coordinator) and then read the data out  over UART1 to another microcontroller which will display it on a computer. However, I don't know where to start with Z Stack!

Where do I actually write the code to do this?

Do I need to write a function to do this in GenericApp.c?

Is Z Stack configured for UART0 by default?

Do I need to enable UART in the compile options?

Many thanks for your help

Ryan

  • The UART interface is exposed through hal_uart.c/h. If you want to use the UART in your application insure that the MT_* predefined symbols are removed from the project options (else the MT module will used the UART), also define HAL_UART=TRUE in the project options so ZStack initializes the UART module. To configure the UART ad the following to your app:

    #include "hal_uart.h"
    void myUartCallBack(uint8 port, uint8 event);

    void APP_UartInit ()
    {
    halUARTCfg_t uartConfig;

    /* UART Configuration */
    uartConfig.configured = TRUE;
    uartConfig.baudRate = HAL_UART_BR_38400;
    uartConfig.flowControl = TRUE;
    uartConfig.flowControlThreshold = 5;
    uartConfig.rx.maxBufSize = 120;
    uartConfig.tx.maxBufSize = 170;
    uartConfig.idleTimeout = 5;
    uartConfig.intEnable = TRUE;
    uartConfig.callBackFunc = myUartCallBack;

    /* Start UART */
    HalUARTOpen (0, &uartConfig);
    }

    The function myUartCallBack will be called when the UART buffer has reached its threshold (rx.maxBufSize - flowControlThreshold), or if there is data for idleTimeout ms. So if you are sure you will only recv 1 byte then you may want to tweak the values.

    void myUartCallBack(uint8 port, uint8 event)
    {
    uint16 bytesRead = 0;
    uint8 *ch;

    //read 1 byte
    bytesRead = HalUARTRead ( port, &ch, 1 );

    /* Do you stuff */

    }

    To write a byte:

    HalUARTWrite ( 0, &ch, 1 );

    Regards,
    TC.
  • Hello,

    Many thanks for detailed answer. I also wanted to ask, is the uart output readable by a regular terminal application like putty or does z stack require z tool to read data such as chars?

    Many thanks

    Ryan
  • MT command is based on hex format. Putty uses char format so it is not suitable for MT command communication. You should use z-tool or terminal tool that supports hex format.
  • If you are using MT then the response from YK is correct. However from your original post I assume you where not using MT and you want the UARt to be in full control of the application. In this case it depends what you send to the UART, if you send:

    ch= 'a';
    HalUARTWrite ( 0, &ch, 1 );

    Then you will see 'a' on a serial terminal such as putty (assuming that you have set the terminal correct for Board Rate, flowcontrol etc).

    Regards,
    TC.