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.

UART configuration for cc2530 with Z-stack home.

Guru 14820 points
Other Parts Discussed in Thread: Z-STACK, CC2530

Hello,

I am working on cc2530 with z-stack home.

I want to configure any of the either port of cc2530 for UART communication.

I found a post on TIE2E-

then I defined the functions as it is in my code..but the serial communication is not working.

#include "ioCC2530.h"

unsigned char output;
//..............................................................................
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
}
//..............................................................................

//..............................................................................
void send(unsigned char c)
{
UTX0IF = 0;
U0DBUF=c;
while (!UTX0IF);
UTX0IF = 0;
}
//..............................................................................

since i only want to send data out so i used only send function.

when I call send function i.e.

send (output);

the program stuck at  

while (!UTX0IF);

  in the send function.

please help to resolve the issue.

Regards 

Dhanraj

  • You can try the following codes. I test it on my CC2530DK without problem.

    // Define size of allocated UART RX/TX buffer (just an example).
    #define SIZE_OF_UART_RX_BUFFER 50
    #define SIZE_OF_UART_TX_BUFFER SIZE_OF_UART_RX_BUFFER

    // UART test characters.
    #define UART_TEST_DATA "Texas Instruments LPRF!"

    // Baudrate = 57.6 kbps (U0BAUD.BAUD_M = 216, U0GCR.BAUD_E = 10), given 32 MHz system clock.
    #define UART_BAUD_M 216
    #define UART_BAUD_E 10

    // Buffer for UART RX/TX.
    static uint8 __xdata uartTxBuffer[SIZE_OF_UART_TX_BUFFER] = UART_TEST_DATA;

    // Prototype for local functions.
    void uart0Send(uint8* uartTxBuf, uint16 uartTxBufLength);


    void main (void)
    {
    /****************************************************************************
    * Clock setup
    * See basic software example "clk_xosc_cc254x"
    */

    // Set system clock source to HS XOSC, with no pre-scaling.
    CLKCONCMD = (CLKCONCMD & ~(CLKCON_OSC | CLKCON_CLKSPD)) | CLKCON_CLKSPD_32M;
    // Wait until clock source has changed.
    while (CLKCONSTA & CLKCON_OSC);

    /* Note the 32 kHz RCOSC starts calibrating, if not disabled. */


    /***************************************************************************
    * Setup I/O ports
    *
    * Port and pins used by USART0 operating in UART-mode, at the Alternative 1
    * location are:
    * RX : P0_2
    * TX : P0_3
    * CT/CTS : P0_4
    * RT/RTS : P0_5
    *
    * These pins must be set to function as peripheral I/O to be used by UART0.
    * The TX pin on the transmitter must be connected to the RX pin on the receiver.
    * If enabling hardware flow control (U0UCR.FLOW = 1) the CT/CTS (Clear-To-Send)
    * on the transmitter must be connected to the RS/RTS (Ready-To-Send) pin on the
    * receiver.
    */
    PERCFG = (PERCFG & ~PERCFG_U0CFG) | PERCFG_U0CFG_ALT1;

    // Give priority to USART 0 over Timer 1 for port 0 pins.
    P2DIR &= P2DIR_PRIP0_USART0;

    // Set pins 2, 3 and 5 as peripheral I/O and pin 4 as GPIO output.
    P0SEL |= BIT5 | BIT4 | BIT3 | BIT2;

    // Initialize P0_1 for SRF05EB S1 button.
    P0SEL &= ~BIT1; // Function as General Purpose I/O.
    P0DIR &= ~BIT1; // Input.

    /***************************************************************************
    * Configure UART
    *
    */

    // Initialise bitrate = 57.6 kbps.
    U0BAUD = UART_BAUD_M;
    U0GCR = (U0GCR & ~U0GCR_BAUD_E) | UART_BAUD_E;

    // Initialise UART protocol (start/stop bit, data bits, parity, etc.):
    // USART mode = UART (U0CSR.MODE = 1)
    U0CSR |= U0CSR_MODE;

    // Start bit level = low => Idle level = high (U0UCR.START = 0).
    U0UCR &= ~U0UCR_START;

    // Stop bit level = high (U0UCR.STOP = 1).
    U0UCR |= U0UCR_STOP;

    // Number of stop bits = 1 (U0UCR.SPB = 0).
    U0UCR &= ~U0UCR_SPB;

    // Parity = disabled (U0UCR.PARITY = 0).
    U0UCR &= ~U0UCR_PARITY;

    // 9-bit data enable = 8 bits transfer (U0UCR.BIT9 = 0).
    U0UCR &= ~U0UCR_BIT9;

    // Level of bit 9 = 0 (U0UCR.D9 = 0), used when U0UCR.BIT9 = 1.
    // Level of bit 9 = 1 (U0UCR.D9 = 1), used when U0UCR.BIT9 = 1.
    // Parity = Even (U0UCR.D9 = 0), used when U0UCR.PARITY = 1.
    // Parity = Odd (U0UCR.D9 = 1), used when U0UCR.PARITY = 1.
    U0UCR &= ~U0UCR_D9;

    // Flow control = disabled (U0UCR.FLOW = 0).
    U0UCR &= ~U0UCR_FLOW;

    // Bit order = LSB first (U0GCR.ORDER = 0).
    U0GCR &= ~U0GCR_ORDER;


    /***************************************************************************
    * Transfer UART data
    */
    while(1)
    {
    uart0Send(uartTxBuffer, SIZE_OF_UART_TX_BUFFER);
    }
    }


    void uart0Send(uint8* uartTxBuf, uint16 uartTxBufLength)
    {
    uint16 uartTxIndex;

    // Clear any pending TX interrupt request (set U0CSR.TX_BYTE = 0).
    U0CSR &= ~U0CSR_TX_BYTE;

    // Loop: send each UART0 sample on the UART0 TX line.
    for (uartTxIndex = 0; uartTxIndex < uartTxBufLength; uartTxIndex++)
    {
    U0DBUF = uartTxBuf[uartTxIndex];
    while(! (U0CSR & U0CSR_TX_BYTE) );
    U0CSR &= ~U0CSR_TX_BYTE;
    }
    }
  • Thank you so much sir!

    finally UART is working after little changes in above code.

    Enabling UART0 for sending data out for debugging purpose.pdf

  • You are welcome.