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.

BLE Stack UART Problem

Other Parts Discussed in Thread: CC2541

Dear All,

I am using BLE Stack 1.3 on CC2541  and trying to send  some serial  data via UART 1. The program crash and reset at the time I set the  IEN2.UTX1IE to 1.

Initialization:

PERCFG |=  PERCFG_U1CFG;

 // Configure relevant Port P1 pins for peripheral function:
 P1SEL |= BIT7 | BIT6;   
  
 // USART mode = UART (U1CSR.MODE = 1)
 U1CSR |= U1CSR_MODE;

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

  // Stop bit level = high (U1UCR.STOP = 1)
  U1UCR |= U1UCR_STOP;

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

  // Parity = disabled (U1UCR.PARITY = 0)
  U1UCR &= ~U1UCR_PARITY;

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

   U1UCR &= ~U1UCR_D9;

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

  // Bit order = LSB first (U1GCR.ORDER = 0)
  U1GCR &= ~U1GCR_ORDER;

UartTxIsr:

// Clear any pending UART TX Interrupt Flag (IRCON2.UTXxIF = 0, UxCSR.TX_BYTE = 0)
 UTX1IF = 0;  
U1CSR &= ~U1CSR_TX_BYTE; U1DBUF = uartTx[uartTxIndx++]; // Enable global interrupt (IEN0.EA = 1) and UART TX Interrupt (IEN2.UTXxIE = 1) EA = 1; IEN2 |= IEN2_UTX1IE;

Please help.

Thanks

 

  • Hello Gilar,

    It is recommended that you use UART 0 and DMA with the BLE stack.  You can find an example of the UART with DMA in the swrc257 http://www.ti.com/litv/zip/swrc257 folder under UART.  It gives examples of using DMA, polling and ISR.  

    Experiment with the examples without BLE first, then incorporate it into your BLE project when you have it working correctly.

    Thanks,

  • I really appreciate your quick response, greenja. Okay, I will try it.

    Thanks,


  • greenja, could you please tell me why should I use Uart0 in this case?

    - because I am using it (Uart0) or I have to use it for another purpose. -

    thanks

  • Hello,

    Even though the versions of IAR are different, you should still be able to use the code found in the swrc257.  On the IAR website somewhere, there are updates that include the header and configuration files for the cc254x devices.  You just have to install them into you IAR devices folder.  Also, you could just copy the code section only and build your own project.

    Using UART0 was either specified somewhere because the other one was being used (it has been a long time since I looked at that code) or I found that it was the only one that worked.

    Thanks,

  • There's nothing to stop you from using either uart. DMA is recommended, though, because ISRs are sometimes delayed by radio operation.

    In the HostTest project, either U0Alt1 or U1Alt2 is used, so the other one is available for you.

    When it crashes after enabling interrupts, this leads me to wonder whether you have defined an ISR vector for that ISR.

    BR,
    Aslak

  • Dear Aslak,

    You are right. But I forgot to tell something that I am using SensorTag example code and the fact that in this SensorTag project the Uart1 makes the program crash at enabling the IEN2 interrupt.

    I tried to find defined vector that maybe overlapped, but I found nothing.

    Please help...

    Thanks

  • Hi Gilar,

    First of all, make sure that you have defined the right ISR. So, define both. Next, put while-1 loops in both ISRs and toggle some LEDs or something. You could also give breakpoints a shot.

    BR,
    Aslak

  • Hi Aslak,

    I found that what happened is not crash and reset, but the BLE dropped the connection due to interrupt priority conflict between RF and UART1 Interrupt. In other side I also use the the interrupt timer 3 to run another task.

    So, I have to move the UART using DMA as you recommend. Before go there, I am still wondering if I could adjust something in BLE stack timer to avoid this problem. The UART01 TX is not primary and not continuously used. Just sometimes with 20ms duration of data transfer. 

    Thanks,

  • Hi Greenja ,

    Here i am facing problem with UART0-Alt2 (Using sensortag board Port-1 ; 4-Rx ,5-Tx , 3-RT , 2-CT) , connected sensortag board with PC using Serial-USB cable , Using UART-ISR method to implement method . My intension to interface ios device with PC ( Like Read data from hyperterminal to light blue app using Read characteristic , and Write data to hyperterminal using write characteristic) I succeed writing data to hyperterminal but when I tried to read data from hyperterminal continuoulsy i am reading 1st typed character only (means it's not taking 2nd character) if i tried to check the condition of Rx_Byte( like: while( !(U0CSR & U0CSR_RX_BYTE) ); it's taking 1st character when i try to type 2nd character the peripheral device is disconnecting from light blue app .( BLE connection losing) . below you can see my code for Receiver:


    void UART0_RECEIVE_ISR(uint8* uartRxBuffer , uint16 uartRxBufLength)
    {

    // Initialize the UART RX buffer index.
    uartRxIndex = 0;

    // Clear any pending UART RX Interrupt Flag (TCON.URXxIF = 0, UxCSR.RX_BYTE = 0).
    URX0IF = 0;

    // Enable UART RX (UxCSR.RE = 1).
    U0CSR |= U0CSR_RE;
    U0CSR &= ~U0CSR_TX_BYTE;

    // Enable global Interrupt (IEN0.EA = 1) and UART RX Interrupt (IEN0.URXxIE = 1).
    URX0IE = 1;
    EA = 1;
    }

    #pragma vector = URX0_VECTOR
    __interrupt void UART0_RX_ISR(void)
    {
    // Clear UART0 RX Interrupt Flag (TCON.URX0IF = 0).
    URX0IF = 0;

    // Read UART0 RX buffer.

    uartRxBuffer[uartRxIndex++] = U0DBUF; // continuosly reading 1st typed character

    // while( !(U0CSR & U0CSR_RX_BYTE) ); // if i use this condition it's causing for Loss of BLE connection

    if( uartRxIndex == UART_DATA_LENGTH) // here Rx buffer size and UART_DATA_LENGTH both are 3
    {
    uartRxIndex = 0;
    U0CSR &= ~U0CSR_RX_BYTE;
    UART_SetParameter(UART_READ ,UART_DATA_LENGTH, &uartRxBuffer); //sizeof(uint8)
    }

    }
  • Hello Kadari,

    You should use the DMA method for UART. There is a uart_0_DMA.c file found in the swrc257 example folder that works well.

    The index in your case is always being set back to zero. Set a breakpoint and create a watch for uartRxIndex and uartRxBuffer. This will at least tell you if your are receiving more than one byte.

    Still, use the DMA method, you will not have any issues with lost data on the serial port.

    Thanks,
  • One more thing. You mention you are using 1.3.0 stack. There are know bugs in the UART driver in that version of the stack. We highly recommend using version 1.4.0.
  • Hi greenza ,

    I tested UART by using 3 methods which is mentioned in swrc257 (Polling , ISR and DMA) , In this by polling and DMA methods are causing an issue like " I was unable to make BLE connection when I call Receive function in the application file . I Board is never connecting with Lightblue app . at the same If i use only Transmission it's working well " . Still I am not understanding how Receiver making an BLE connection issue
  • Hello Kadari,

    You need to create a _Uart_Event_Timer and set a reasonable period for this event.

    When that Event is called, then you can check to see anything has been received by the UART. The simple method would be to put some kind of flag in the _interrupt void DMA_ISR(void).

    My method is to have only this in the section that says:
    // Star a new UART RX session ...
    If (DMAIRQ & DMAIRQ_DMAIF0)
    {
    // Indicate...
    uartPktReceived =1;
    // Clear DMA...
    DMAIRQ = ~DMAIRQ_DMAIF0;
    }

    Then inside your UART event, you check to see if this flag is set. If is set, then you clear the flag, re-arm the DMA channel and execute whatever procedure you want for on the received data.

    You never want to put any type of loop where if a condition fails it stays in that loop. If you are using a while loop, then you should have either a counter or timer to exit that loop after a certain time. This will prevent the loss of BLE connection.

    Thanks,