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.

cc2540 read data via uart

Other Parts Discussed in Thread: BLE-STACK, CC2540

Hi,

Is there any sample code to show how the uart work in BLE-stack v1.3?

I tried to read the data send through uart, and then send to Btool. But the data is always 0 in Btool, whatever I sent in uart. (I am sure that the ble transmit part works properly.)

I have tried to define the register by hand and read the U0DBUF directly. or using HAL_UART, but neither works.

i have pasted my test code on another post (http://e2e.ti.com/support/low_power_rf/f/538/p/251738/883793.aspx#883793).

So does anyone has successfully used cc2540 to read uart signal by using BLE-stack v1.3, and could kindly help me with it?

Thanks a lot!

By the way, I have tried to read the project Serialapp, but i did not find the way it does to read data from uart and then send to ble. what's more, when i try to compile it, a error comes out, says

"Error[Pe020]: identifier "HCI_ProcessEvent" is undefined D:\Texas Instruments\BLE-CC254x-1.3\Projects\ble\SerialApp\Source\OSAL_SerialAppPeripheral.c 90"

  • Hello Hanjie,

    If you haven't resolved this problem yet, I would suggest that instead of trying to send to Btool, send your data to HyperTerminal or any other terminal program.

    If  you can see the correct data in there, then you know for sure the UART is working correctly.  Then change you _setParameter correctly.  In your other post there is an error with the *lenof(uint8) which shouldn't be there.

    Thanks,

  • Hi, greenja

    thanks for your help, i have successed in receiving from uart last night.

    I added a line

    while ((U0CSR & 0x04) == 0);

    to ensure every time when I read the U0DBUF, the register has already saved the right value.

    otherwise, without that line I will always receive 0xFF.

    But in this case, i have to use a RX isr, since I cant set a while in a task, which will freeze the whole system when no data comes in uart.

    And I faced a new problem, even if i enabled the RX interupt, the program never goes in to the RX_isr.

    the code to enable interupt is like this:

      PERCFG |= 0x00;     //usart0 alt.1
        
        
        U0GCR = 11;
        U0BAUD = 216;
        U0CSR |= 0x80;       //uart mode
        U0UCR = 0x02;       //low start bit, high end bit
        
        
           
        URX0IF = 0;
        U0CSR |= 0x40;
        IEN0 |= 0x04;
        IEN0 |= 0x80;

    and the isr is defined below:

    #pragma vector=0x13
    __interrupt void UART0_RX_ISR(void)
    {
     
     
      URX0IF = 0;
      while ((U0CSR & 0x04) == 0);
      uarttemp = U0DBUF;
      uartRxBuffer[uartRxIndex++] = uarttemp;
      if (uartRxIndex >= SIZE_OF_UART_RX_BUFFER)
      {
      uartRxIndex = 0;
      }
      IEN0 &= ~0x04;
    }

    But this cant work. I want to know where is the problem....

    Thanks!

  • I try to initialize uarttemp with value 0xa5,

    and then i use the isr below:

    #pragma vector=0x13
    __interrupt void UART0_RX_ISR(void)
    {
     
     
      URX0IF = 0;
      while ((U0CSR & 0x04) == 0);
      //uarttemp = U0DBUF;
      uarttemp = 0x11;
      uartRxBuffer[uartRxIndex++] = uarttemp;
      if (uartRxIndex >= SIZE_OF_UART_RX_BUFFER)
      {
      uartRxIndex = 0;
      }
      IEN0 &= ~0x04;
    }

    the data i reveived is just 0xa5 but not 0x11, which means it seems that the the program just never goes into the RX_isr.....

  • Do a Find in All Files (Alt Shift F4 or something like that), search current project and search for UART0_RX_ISR. There is another one that is being called instead.  Comment out the one you created and post you code in the other one that you find.

  • i used the find in all files, the result is


    "Found 1 instances. Searched in 103 files."

    and there are lots of files failed to read

    the only found 1 is just what i defined...

  • All those failed to read files means that they have not been added to your project.  You can try just polling the the HalUARTPoll() in your code or you can experiment with what is suggested below.

    Use one of the existing projects from the Project folder and modify it.  You can make a copy of the testRelease example.  In the HostTest_main.c, comment out the osal_start_system() and then try communicating with Btool.

    You can read from the USB using:

      // Poll USB for data is using USB Dongle
      HalUARTPoll();
      if (USB_data_ready){
        HalUARTRead(HAL_UART_PORT_0,msg_buf1,cntr);
        HalUARTRx(msg_buf1, 8);
        READ_COMMAND();
        USB_data_ready = 0;
      }
    The READ_COMMAND() routine is your own parsing routine to read what is in msg_buf1 or any buffer that that you define.  The USB_data_ready flag is placed in the USB or UART ISR, I don't have the entire code with me, but it was placed in one of them.  You will just have to search through the code and follow how and where the HalUARTRead and Rx are being used.
    To send to the USB use:

     HalUARTWrite(HAL_UART_PORT_0,trans_buf,trans_size);

    You define the trans_buf and the trans size is the number of bytes in the buffer.

    Thanks,

  • Hi, I am getting the same error:

    "Error[Pe020]: identifier "HCI_ProcessEvent" is undefined D:\Texas Instruments\BLE-CC254x-1.3\Projects\ble\SerialApp\Source\OSAL_SerialAppPeripheral.c 90"


    Did you ever find a solution to this problem?  I have followed the instructions here:

    http://processors.wiki.ti.com/index.php/LPRF_BLE_Porting_Projects


    But still the problem exists.


    EDIT: I've added 

    #include "hci_tl.h"

    to OSAL_SerialAppPeripheral.c, and that error goes away, and a new error appears:

    Linking
    Error[e104]: Failed to fit all segments into specified ranges. Problem discovered in segment XDATA_N. Unable to place
    2 block(s) (0xc02 byte(s) total) in 0x9b5 byte(s) of memory. The problem occurred while processing the segment
    placement command "-P(XDATA)XDATA_N=_XDATA_START-_XDATA_END", where at the moment of placement the
    available memory ranges were "XDATA:154b-1eff"

    I have changed the TX and RX buffer sizes down to 8 bytes in serialAppUtil.h, and still get this error.

    Is it possible to just download the version 1.2 BLE library from somewhere?

    EDIT: found the older BLE stack 1.2.1 version here and will try:

    http://e2e.ti.com/support/low_power_rf/f/538/t/248191.aspx


  • Hi TI User1

    I'm having exactly the same problem.

    Did you find a solution or are you using the version 1.2?

    thanks :)