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.

HELP USING UART ON CC2530

Other Parts Discussed in Thread: TIMAC, CC2530, CC2530EM, Z-STACK

Hi,

I'm new in micro programming and in UART interface.

I use  CC2530  with  TIMAC to develop my Wireless Sensor Network. Now I have to comunicate with a GSM modem by UART and  AT Commands, but I've never used UART.

As first step I would like to implement, on a Smart RF05, a RS232 interface to communicate with hyperterminal: just to understand how to transmit and receive a char.

I've read the "HAL Driver API.pdf" but I didn't understand how to use the functions.

 

Does exists a simple example about how to use uart interface with TIMAC and CC2530 ?

Can anyone help me ?

 

Thanks in advance.

  • Hi Recardo,

    As a first step, you probably have to understand how the UART works in CC2530,

    please consider reading the DN112, It'll give you a general overview and better

    understanding of UART and working with cc253x concepts.

    Farther, you can go back to the "HAL driver API" document (UART section)

    and use the suggested functions, which are wrappers of the code presented

    in DN112 (in most cases).

    With better understanding of the UART and cc2530 manipulation you can

    post question on the forum if you stuck or having doubts..

    You may also consider to post your questions on the topic in the ZigBee forum:

    "Low Power RF ZigBee® Software & IEEE 802.15.4" (You'll find a lot of valuable

    info regarding cc2530 SoC and UART issues there).

    Hope it helps. :)

     

    Br,

    Igor

  • Hi Igor,

    Thanks a lot for your advice, I will read DN112 as soon as possible :) !

  • Hi,

    I've read the UART application notes DN112 and understood it more then "HAL driver API" document.

    So I'm trying to print and receive a char on hyperterminal copying the examples and functions in the application notes.

    I've set a connection as follow:

    uartProtConfig.uartNum = 1;

      uartProtConfig.START  = 0; // low start bit 

      uartProtConfig.STOP    = 1; // hihg stop bit 

      uartProtConfig.SPB     = 0; // 1stop bit

      uartProtConfig.PARITY  = 0; // no parity

      uartProtConfig.BIT9    = 0; // no 9th bit

      uartProtConfig.D9      = 0; // x

      uartProtConfig.FLOW    = 1; // enable HW flow control

      uartProtConfig.ORDER   = 0; // LSB first

    uartInitProtocol(&uartProtConfig);

    with Baudrate = 2400:

    U0BAUD = 0x3B; 

      U0GCR = (U0GCR &~ 0x1F) | 0x06;

    and I've allocated a TX and RX buffer:

    unsigned short __xdata uartRxBuffer[SIZE_OF_UART_RX_BUFFER];

    unsigned short __xdata uartTxBuffer[SIZE_OF_UART_TX_BUFFER];

    uartTxBuffer[0] = 0x48; // H uartTxBuffer[1] = 0x45; // E uartTxBuffer[2] = 0x4C; // L uartTxBuffer[3] = 0x4C; // L uartTxBuffer[4] = 0x4F; // O

    Then I try to transmit TX buffer over RS232 (on Smart RF05) to hyperterminal with interrupt (NO DMA):

      uartStartTxForIsr(0);

     

    /*************************************************************************************************************/

    void uartStartTxForIsr(unsigned char uartNum) {

      uartTxIndex = 0; 

      if (uartNum == 0) {

        UTX0IF = 0;  

        IEN2 |= 0x04;

        U0DBUF = uartTxBuffer[uartTxIndex++];

      } else {

        UTX1IF = 0;

        IEN2 |= 0x08;

        U1DBUF = uartTxBuffer[uartTxIndex++];

    }

      IEN0 |= 0x80; // enable global interrupt (IEN0.IE = 1)

    }

    _Pragma("vector=0x3B") __near_func __interrupt void UART0_TX_ISR(void){

      UTX0IF = 0; // clear tx flag 

      if (uartTxIndex >= SIZE_OF_UART_TX_BUFFER) {

        uartTxIndex = 0;

        IEN2 &= ~0x04;

        HalLedSet (HAL_LED_1, HAL_LED_MODE_ON);

        return;

      }

      U0DBUF = uartTxBuffer[uartTxIndex++];

    }

    /**************************************************************************************************************/

     

    I see LED1 ON (end of tx) but on the console I dont' see anything !

    Have I missed any step ?

    Of course Hyperterminal is setted with the same value of UART.

    Need I to configure anything else ?

     

    Thanks in advance for any help !

     

  • Hi Riccardo,

     

    I'll take a look in your code a little bit later.

    Meanwhile check if the "RS232 Enable switch" (P14 - left to the

    DB-9 connector) on your smartRF05EB is in "Enable" mode.

     

    Br,

    Igor

  • Hi Igor,

     

    Thank you very much because I'm really stuck...

    Yes RS232 is enable but I can't still see anything.

     

    Thanks!

    Riccardo

  • Hi Ricardo,

     

    Lets go step by step.

    Your code seems to be alright (Besides, your getting some sort of indication

    about "end of transmission" and that is a good sign) .

    However, some information is still missing:

    1. How exactly you connecting your cc2530 SoC with PC, What are the
      interconnections? Can you please describe it in a more detailed way?
      (Schematic, if your using Serial To USB, etc.)
    2. In your code, I haven't noticed any configuration mapping UART0 to
      specific SoC's port? Assuming "After Reset" SoC configuration, you
      have connected your PC R232 cable to pins; P2, P3, P4, P5 on PORT_0,
      Is that the case?

    One more thing, you haven't mentioned it before, do you have any Evaluation

    Board for cc2530 SoC, or it is just your own custom board you are experimenting

    with?

     

    Br,

    Igor

  • Hi Igor,

     

    1.  To connect the cc2530EM with PC I use the RS232 port in the Smart RF05 EB 1.8.1 with a RS232/USB converter (It has always worked fine).

    2.  In the previous post I've not reported the configuration of the port, that is:

    // UART0, Alternative 1

    PERCFG &= ~0x01;

      P0SEL |= 0x3C;

      P1SEL &= ~0x3C;

    // Set Bitrate

    CLKCONCMD &= 0x80;

    while(CLKCONCMD & 0x40);

    SLEEPCMD |= 0x04;

    U0BAUD = 0x3B;

    U0GCR = (U0GCR &~ 0x1F) | 0x06;

     

    Thanks again.

     

    Riccardo.

  • Hi Riccardo,

     

    Please forgive it took me so long to answer you.

    From reading your last post, I'm not really understands why

    in the "Set Bitrate" you are involving CLKCONCMD and SLEEPCMD

    registers?

     

    One more thing, it may be sounds a little bit odd, but, can you please

    check that the RS232 on EB and RS232/USB converter driving the same

    voltage levels (it may be so that the RS232 on EB driving +-12v where 

    converter drivin 0v to 3.3v.)

     

    Br,

    Igor

  • Hi Igor,

    dont' worry... I was on holiday until last week !

    In "Set Bitrate" I've involved CLKCONCMD  and SLEEPCMD just to replicate the application note (page 13). However I think it's not needed.

    These days I've tryed again the API functions and maybe I've found the problem: in "hal_board_cfg.h" there's a variable named HAL_UART that in my application remained FALSE. I don't know why in that file there's an if condition to set it TRUE:

    #ifndef HAL_UART

    #if (defined ZAPP_P1) || (defined ZAPP_P2) || (defined ZTOOL_P1) || (defined ZTOOL_P2)

    #define HAL_UART TRUE

    #else

    #define HAL_UART FALSE

    #endif

    #endif

    If I bypass the test and set HAL_UART = TRUE the uart seems work fine with API !

    Without API (using the function cited in the earlier posts) it seems work fine only using polling, using interrupts I see on the console just the first char, but not the others, and the led remain OFF (it doesn't reach the end of transmission).

     

    What do you think about setting HAL_UART = TRUE ?

     

    Thanks

     

    Riccardo

  • Hi Riccardo,

     

    The HAL_xxxx type of flags are used as a precompile flags

    to turn ON/OFF HAL drivers implemented in Z-Stack, like

    HAL_UART, HAL_LCD, HAL_ADC, etc...

    So basically all the implemented HAL drivers are ON by

    default and it is important to keep those on if you intended

    to use a specific driver. In other words, setting HAL_UART

    =TRUE in the first place allowing you to use the UART API.

    More information on this can be found in "Z-Stack HAL

    Porting Guide.pdf" document, section 2.2. (In your Z-Stack

    installation folder/Documents).

     

    Hope this helps,

    Igor.

     

     

  • Thank you very much for your help Igor.

    Now UART seems ok!

  • Hi Ricardo, I am Carolina and Iam working with CC2530, I have the same problem that you had, could you show me the whole code, please? The code that I am looking for is for communicating with UART... thank you so much.

  • Hi Carolina,

     

    In case you are using Z-Stack, I strongly suggest you to use the UART API

    (you can find this api in HAL_API.pdf, under the UART section).

     

    Br,

    Igor

  • Hi Carolina,

    as Igor says, the simplest way is to use UART API described in "HAL Driver API.pdf". 

    Now I use them with CC2530 and TIMAC, UART works fine.

    First I've modified the file "hal_board_cfg.h" to set HAL_UART = TRUE:

     

    #ifndef HAL_UART

    // #if (defined ZAPP_P1) || (defined ZAPP_P2) || (defined ZTOOL_P1) || (defined ZTOOL_P2)

    #define HAL_UART TRUE

    // #else

    // #define HAL_UART FALSE

    // #endif

    #endif

     

     

    Then set UART parameters and open the port:

      halUARTCfg_t uartConfig;

     

      uartConfig.configured           = TRUE;              // 2x30 don't care - see uart driver.

      uartConfig.baudRate             = SERIAL_APP_BAUD;

      uartConfig.flowControl          = TRUE;

      uartConfig.flowControlThreshold = SERIAL_APP_THRESH; // 2x30 don't care - see uart driver.

      uartConfig.rx.maxBufSize        = SERIAL_APP_RX_SZ;  // 2x30 don't care - see uart driver.

      uartConfig.tx.maxBufSize        = SERIAL_APP_TX_SZ;  // 2x30 don't care - see uart driver.

      uartConfig.idleTimeout          = SERIAL_APP_IDLE;   // 2x30 don't care - see uart driver.

      uartConfig.intEnable            = TRUE;              // 2x30 don't care - see uart driver.

      uartConfig.callBackFunc         = UartCallBack;

      HalUARTOpen (SERIAL_APP_PORT, &uartConfig);

    Now you can use the UART port

     HalUARTWrite(SERIAL_APP_PORT, *str, len);

     

    Hope it helps!

     

    Riccardo

    8117.HAL Driver API.pdf

     

  • Hi,

    I am a student and new to embedded programming. As part of my academic project my requirement is to read a string sent from a client program to serial port. I need to use the Smart RF05 board to read the string from the serial port and display it on its LCD screen. I use a RS232 cable (serial port to USB) to connect my laptop and the Smart RF05.

    Am experiencing problems using halUartRead() to read the character from the serial port. Actually I am not able to read the string sent from my clientapp and display it on the LCD screen. Pls note that I'm not using Z-Stack. Here is the code snippet :

    static void appTestRecieve()

    {

      uint8 buf[5];

      uint16 length = 5;

      int i=0;

      int result = 0;

      while (TRUE)

      {

         // halUartRead return number of bytes it read

         result = halUartRead(buf, length);

         if(result != 0)

         {

            halLcdClear();

            while(i<5)

            {

             halLcdWriteChar(iLineCount, iColCount, buf[i]);

         i++;

             }

          }

      }

    }

     

    WHile debugging I found out that the "result" remains as 0 even after halUartRead() is called. Hence the code inside the IF condition is not executed.

    My client app is stable and does not produce any exceptions/errors when I run it indicating that it might be a problem in the coordinator code that I've written.

    Any help would be greatly appreciated. Thanks

     

    Arthur

  • Hi there,

     

    Few things:

    1. While halUartRead() is a common name to this kind of functions,, it is really good to know
      what's inside this function, may be the buggy behavior lies inside it.
    2. May be you misplaced it, or didn't remember to mention it, but I see no UART configurations;
      IO configurations as peripherals, baud rate, etc...
    3. You can always use HW debugger (oscilloscope) to observe serial traffic on TX and RX pins.
      Plus the FW (I mean the IAR EW) debugging in this case may put some light on several 
      issues, use breakpoints to check potential pitfalls.

    Hope this helps

  • Hi Igor,

    Thank you very much for the reply.

    As per your suggestion I took a look inside the halUartRead() and found out that it was not enough for what I need. On further study I found out two methods from Design Note DN112 'SWRA222b' by TI (http://www.ti.com/lit/an/swra222b/swra222b.pdf). These were based on UART RX Processing using UART Polling.
    void uart0Receive(unsigned short* uartRxBuf, unsigned short uartRxBufLength);
    void uart1Receive(unsigned short* uartRxBuf, unsigned short uartRxBufLength);


    However I am still not able to read any character sent from my client program. I can safely say that the client program is running fine. I could see the RS-232 cable blink when the client program is run indicating data transfer is happening. But we are not able to receive it on the board. I have pasted the code below.
    For debugging purpose I have made use of halLcdWriteChar() to find out where the program is failing. I am able to see until output "F" on the smartRF05 board [ inside function uart0Receive() ] but there is no response after that. Below is the code that i've written:

    /***********************************************************************************
    * INCLUDES
    */

    /***********************************************************************************
    * LOCAL CONSTANTS and DEFINITIONS
    */
    // Baud rate settings
    #if BSP_CONFIG_CLOCK_MHZ==32

    #define BAUD_M_38400                 59
    #define BAUD_M_57600                216
    #define BAUD_M_115200               216

    #define BAUD_E_38400                 10
    #define BAUD_E_57600                 10
    #define BAUD_E_115200                11

    #elif BSP_CONFIG_CLOCK_MHZ==26

    #define BAUD_M_38400                131
    #define BAUD_M_57600                 34
    #define BAUD_M_115200                34

    #define BAUD_E_38400                 10
    #define BAUD_E_57600                 11
    #define BAUD_E_115200                12

    #elif BSP_CONFIG_CLOCK_MHZ==24

    #define BAUD_M_38400                163
    #define BAUD_M_57600                 59
    #define BAUD_M_115200                59

    #define BAUD_E_38400                 10
    #define BAUD_E_57600                 11
    #define BAUD_E_115200                12

    #else
    #error "Clock speed not defined!"
    #endif
    /***********************************************************************************/
    static Packet_t rxPacket;
    static Uart_packet upacket;
    int16 rssi;
    uint8 check;
    int timer_count,timer_count1;
    uint8 uart0Receive(unsigned short* uartRxBuf, unsigned short uartRxBufLength);
    uint8 uart1Receive(unsigned short* uartRxBuf, unsigned short uartRxBufLength);

    /***********************************************************************************
    * @fn          main
    * @brief       This is the main entry of the "Coordinator" application.
    *              Intialized the RF Communication and UART         
    * @return      none
    */
    void main(void)
    {
        check = 0;
        upacket.AssetTag_ID = 1;
        upacket.LocTag_ID = 1;
        upacket.AssetTagLQI = 0;
        timer_count = 0;
        timer_count1 = 0;
        battCheckCount = 0;
        basicRfConfig.myAddr = LOCATION_1_ADDR;             // Set address
        basicRfConfig.panId = PAN_ID;
        basicRfConfig.channel = RF_CHANNEL;
        basicRfConfig.ackRequest = FALSE;

        halBoardInit();
       
        if(halRfInit()==FAILED) {
          HAL_ASSERT(FALSE);
        }
        halTimer32kInit(TIME_OUT_INTERVAL);
        halTimer32kIntConnect(&appTimerISR);
        halUartInit(HAL_UART_BAUDRATE_57600,0);
       
        halLcdWriteChar(1, 1, 'A');    //for testing purpose
       
        appTestTransmit();  
    }

    /* To Read from UART/serial port
    *
    *
    */
    static void appTestTransmit()
    {
      unsigned short buf[2];
      uint16 length = 2;
      int result = 0;
     
      while (TRUE)
      {
           result = uart0Receive(buf,length);
           if(result != 0)
           {
                halLcdClear();
                halLcdWriteChar(1, 0, 'x');
           }
           else if (result == 0)
           {
              result = uart1Receive(buf,length);
              if(result != 0)
              {
                halLcdClear();
                halLcdWriteChar(1, 0, 'y');
              }
              else if(result == 0)
              {
                halLcdClear();
                halLcdWriteChar(1, 0, 'E');
              }
           }
      }
    }

    uint8 uart0Receive(unsigned short* uartRxBuf, unsigned short uartRxBufLength)
    {
      uint8 i=0;
      unsigned short uartRxIndex;
      U0CSR |= 0x40; URX0IF = 0;
      uartRxIndex = 0;
     
      halLcdClear();
      halLcdWriteChar(1, 0, 'F');    // Reaches here **
     
      while( !URX0IF );        //Wait until data received (URXxIF = 1).
     
      halLcdClear();
      halLcdWriteChar(1, 0, 'G');    //Means exit from loop, data received URX0IF = 1
      uartRxBuf[uartRxIndex] = U0DBUF;
      URX0IF = 0;
      i = 1;
      return i;
    }

    uint8 uart1Receive(unsigned short* uartRxBuf, unsigned short uartRxBufLength)
    {
      uint8 i=0;
      unsigned short uartRxIndex;
      U1CSR |= 0x40; URX1IF = 0;

      uartRxIndex = 0;
      halLcdClear();
      halLcdWriteChar(1, 0, 'H');
     
      while( !URX1IF );
      halLcdClear();
      halLcdWriteChar(1, 0, 'I');
     
      uartRxBuf[uartRxIndex] = U1DBUF;
      URX1IF = 0;
      i = 1;
      return i;
    }

    I am lost and I don't know how if it is some error in my program or that I am missing something here. Can you please provide some help. Tks

  • Forgot to paste the halUartInit() definition. Here it is:

    /***********************************************************************************

      Filename:     hal_uart_cc8051.c

      Description:  UART interface to UART0 at P0. Works with HW flow control and
                    optionally with buffered TX transmission. Reception is always
                    buffered. Works with 8051 based SoCs.

    ***********************************************************************************/
    * INCLUDES
    */
    /***********************************************************************************
    * LOCAL CONSTANTS and DEFINITIONS
    */

    #define xHAL_UART_TX_POLLING

    #define P2DIR_PRIPO               0xC0
    #define HAL_UART_PRIPO            0x00

    #define HAL_UART_0_PERCFG_BIT     0x01  // USART0 on P0, so clear this bit.
    #define HAL_UART_0_P0_RX_TX       0x0C  // Peripheral I/O Select for Rx/Tx.

    // UxCSR - USART Control and Status Register.
    #define CSR_MODE                  0x80
    #define CSR_RE                    0x40
    #define CSR_SLAVE                 0x20
    #define CSR_FE                    0x10
    #define CSR_ERR                   0x08
    #define CSR_RX_BYTE               0x04
    #define CSR_TX_BYTE               0x02
    #define CSR_ACTIVE                0x01

    // UxUCR - USART UART Control Register.
    #define UCR_FLUSH                 0x80
    #define UCR_FLOW                  0x40
    #define UCR_D9                    0x20
    #define UCR_BIT9                  0x10
    #define UCR_PARITY                0x08
    #define UCR_SPB                   0x04
    #define UCR_STOP                  0x02
    #define UCR_START                 0x01

    #define UTX0IE                    0x04
    #define UTX1IE                    0x08


    /************************************************************************************
    * LOCAL VARIABLES
    */
    static ringBuf_t rbRxBuf;
    #ifndef HAL_UART_TX_POLLING
    static ringBuf_t rbTxBuf;
    #endif


    // Baud rate settings
    #if BSP_CONFIG_CLOCK_MHZ==32

    #define BAUD_M_38400                 59
    #define BAUD_M_57600                216
    #define BAUD_M_115200               216

    #define BAUD_E_38400                 10
    #define BAUD_E_57600                 10
    #define BAUD_E_115200                11

    #elif BSP_CONFIG_CLOCK_MHZ==26

    #define BAUD_M_38400                131
    #define BAUD_M_57600                 34
    #define BAUD_M_115200                34

    #define BAUD_E_38400                 10
    #define BAUD_E_57600                 11
    #define BAUD_E_115200                12

    #elif BSP_CONFIG_CLOCK_MHZ==24

    #define BAUD_M_38400                163
    #define BAUD_M_57600                 59
    #define BAUD_M_115200                59

    #define BAUD_E_38400                 10
    #define BAUD_E_57600                 11
    #define BAUD_E_115200                12

    #else
    #error "Clock speed not defined!"
    #endif

    /************************************************************************************
    * @fn      halUartInit
    * @brief   Initalise UART. Supported baudrates are: 38400, 57600 and 115200
    * @param   uint8 baudrate
    *          uint8 options - this parameter is ignored
    * @return  none
    */
    void halUartInit(uint8 baudrate, uint8 options)
    {
        // Set P2 priority - USART0 over USART1 if both are defined.
        P2DIR &= ~P2DIR_PRIPO;
        P2DIR |= HAL_UART_PRIPO;
       
        // Set UART0 I/O location to P0.
        PERCFG &= ~HAL_UART_0_PERCFG_BIT;
       
        // Enable Tx and Rx on P0
        P0SEL |= (HAL_UART_0_P0_RX_TX);
        P1SEL &= ~(HAL_UART_0_P0_RX_TX);
       
        // Make sure ADC doesnt use this
        ADCCFG &= ~(HAL_UART_0_P0_RX_TX);
       
        U0CSR=  CSR_MODE;             // UART mode
        U0UCR|= UCR_FLUSH;
       
        // Set baud rate
        switch (baudrate) {
        case HAL_UART_BAUDRATE_38400:
            U0BAUD = BAUD_M_38400;
            U0GCR = BAUD_E_38400;
            break;
        case HAL_UART_BAUDRATE_57600:
            U0BAUD = BAUD_M_57600;
            U0GCR = BAUD_E_57600;
            break;
        default:
            // 115200 default
            U0BAUD = BAUD_M_115200;
            U0GCR = BAUD_E_115200;
        }
       
       
        // Initialize the RX buffer
        bufInit(&rbRxBuf);
       
    #ifndef HAL_UART_TX_POLLING
        // Enable transmit register empty interrupt
        UTX0IF= 1;
       
        bufInit(&rbTxBuf);
    #endif
       
        // Set RTS pin to output
        HAL_RTS_DIR_OUT();
       
        // One stop bit
        U0UCR |= UCR_STOP;
       
        // Prepare for reception
        URX0IF = 0;      
        U0CSR |= CSR_RE;
        URX0IE = 1;
       
        // Enable HW flow control
        halUartEnableRxFlow(TRUE);
    }

     

  • hello all,

    i am working on cc2530 kit. I have initialised the uart in GenericApp as follows:

    halUARTCfg_t uartConfig;

    uartConfig.configured = TRUE; // 2x30 don't care - see uart driver.
    uartConfig.baudRate = HAL_UART_BR_9600;
    uartConfig.flowControl = FALSE;
    uartConfig.flowControlThreshold = SERIAL_APP_THRESH; // 2x30 don't care - see uart driver.
    uartConfig.rx.maxBufSize = SERIAL_APP_RX_SZ; // 2x30 don't care - see uart driver.
    uartConfig.tx.maxBufSize = SERIAL_APP_TX_SZ; // 2x30 don't care - see uart driver.
    uartConfig.idleTimeout = SERIAL_APP_IDLE; // 2x30 don't care - see uart driver.
    uartConfig.intEnable = FALSE; // 2x30 don't care - see uart driver.
    uartConfig.callBackFunc = SerialApp_CallBack;
    HalUARTOpen (HAL_UART_PORT_0, &uartConfig);

    And I am also sending data to hyperterminal using following

    uint8 msg[5]={65,66,67,68,69};
    HalUARTWrite(SERIAL_APP_PORT, msg, 5) ;

    I can see the message on the hyperterminal but i also see the the lines that are displayed in the LCD of the EM board.

    I want only the data sent to be displayed,i.e., the contents of "msg". What should i do?

  • If you want to test UART on CC2530, try this echo example:

    #include "ioCC2530.h"
    //..............................................................................
    void initUART(void) //sets all configurations in UART
    {
    CLKCONCMD = CLKCONSTA & 0xB8; //clock control
    while(CLKCONSTA & 0x40);

    PERCFG&=~0x01; //Alernative 1 selected for UART0 peripheral.
    P0SEL |= 0x0C; //P0.2 and P0.3 peripheral mode enabled.
    U0CSR |= 0xC0; //UART mode selected for USART0.
    U0UCR |= 0x00; //H/w flow control disabled
    U0GCR |= 0x08;
    U0BAUD = 0x3b; //Baud rate set to 9600 bps
    }
    //..............................................................................
    char receive (void) 
    {
    URX0IF = 0;     //interrupt flag
    while (!URX0IF ); 
    U0DBUF; //USART 0 Receive/Transmit Data Buffer
    URX0IF = 0;
    return U0DBUF;
    }
    //..............................................................................
    void send(unsigned char c) 
    {
    UTX0IF = 0; 
    U0DBUF=c; 
    while (!UTX0IF); 
    UTX0IF = 0;
    }
    //..............................................................................
    void main()
    {
    initUART(); 

    while(1)
    {
    unsigned char uartdat;
    uartdat=receive();
    send(uartdat);
    }
    }

    Tested on:

    CC2530 Development Kit;

    IAR Workbench for 8051 v 7.60.1;

    PuTTY Terminal