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.

Making UART work on CC2541

So i'm trying to add UART functionality to my project on SensorTag board.

Here's how the initialisation happens:

First, main() function calls HalDriverInit(), which calls HalUARTInit(), which calls HalUARTInitDMA(), since i've configured UART to work in DMA mode using HAL_UART_DMA = 2 symbol.

Then i initialise UART parameters in MyApplication_Init() function the following way:

  {
    halUARTCfg_t uartConfig;

    uartConfig.configured           = TRUE;
    uartConfig.baudRate             = HAL_UART_BR_9600;
    uartConfig.flowControl          = FALSE;
    uartConfig.flowControlThreshold = 0;
    uartConfig.rx.maxBufSize        = 128;
    uartConfig.tx.maxBufSize        = 128;
    uartConfig.idleTimeout          = 10;
    uartConfig.intEnable            = TRUE;
    uartConfig.callBackFunc         = (halUARTCBack_t)UART_CB;

    // start UART
    // Note: Assumes no issue opening UART port.
    if ( HalUARTOpen( HAL_UART_PORT_1, &uartConfig ) != HAL_UART_SUCCESS )
      HalLedBlink( HAL_LED_2, 15, 50, 50 );
    else
    {
      uint8 *msg = "UART configured";
      uint8 msgLen = strlen(msg);
      if (HalUARTWrite(HAL_UART_PORT_1, msg, msgLen) != msgLen)
        HalLedBlink( HAL_LED_2, 15, 50, 50 );
    }
  }

No blinking happens, so i know the configuration is successful and the message has been sent. However, i can see no signal on the Tx pin (P1.5). Why?

  • Hi,

    SensorTag exposes only USART0 only with Alt-2 lines. Defining HAL_UART_DMA alone will not do the trick.  So you need changes in your pin mapping configuration to reflect the correct pins and configure your registers accordingly.

    Please apply the following settings

    /* Test USART 0 on P1.4 and P1.5 */

    PERCFG |= 0x01; // Set UART0 to Alternative 2 location

    P1SEL |= 0x30;

    U0CSR |= 0x80;  // USART mode = UART (UxCSR.MODE = 1)

    U0UCR |= 0x01; // Start bit level = high => Idle level = low (U1UCR.START = 1)

    U0UCR &= ~0x02; // Stop bit level = low (U1UCR.STOP = 0)

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

    U0UCR |= 0x08; // Parity = enabled (U1UCR.PARITY = 1) 

    U0UCR &= ~0x10; // 9-bit data disable = 8 bits transfer (U1UCR.BIT9 = 0)

    U0UCR |= 0x20; // Parity = Even (U1UCR.D9 = 0)

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

    U0GCR &= ~0x20; // Bit order = LSB first (U1GCR.ORDER = 0) => For PC/Hyperterminal

    U0BAUD = 59; // BAUD_M = 59 and BAUD_E = 8 => Baud rate of 9600

    U0GCR &= ~0x1F; // Clear BAUD_E bits

    U0GCR |= 0x08; // BAUD_E = 8

    Also disable UART flow control UART_FC  =  FALSE( in NPI.h)

    Regards,

    Arun

  • Please make the changes as given below

    While building the project, we had the following symbols enabled in our pre processor.

    HAL_DMA=TRUE

    HAL_LCD=FALSE

    HAL_UART=TRUE

    HAL_UART_DMA=1

    HAL_KEY=FALSE

    NPI_UART_PORT=HAL_UART_PORT_0

    We had turned of the flow control in NPI.h - #define NPI_UART_FC FALSE

    Also in _hal_uart_dma.c we did the following register changes.

    #if    (HAL_UART_DMA == 1)

    #define PxSEL                                            P1SEL
    #define HAL_UART_PERCFG_BIT           0x01 // USART0 on P1, Alt-2; 
    #define HAL_UART_PRIPO                      0x00 // USART0 priority over UART1.
    #define HAL_UART_Px_CTS                    0x04 // Peripheral I/O Select for CTS flow control.
    #define HAL_UART_Px_RTS                    0x08 // Peripheral I/O Select for RTS must be manual.
    #define HAL_UART_Px_SEL                    0x30 // Peripheral I/O Select for Rx/Tx.

    .

    .

    .

    #if (HAL_UART_DMA == 1)
    #define PxDIR                         P1DIR
    #define PxIEN                         P1IEN
    #define PxIFG                         P1IFG
    #define PxIF                            P1IF
    #define DMA_RDYIn               P1_2
    #define DMA_RDYOut            P1_3

    Also in HalUARTInitDMA() set PERCFG |= HAL_UART_PERCFG_BIT

    Regards,

    Arun