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.

CC2640 How to receive UART data by interrupt mode

Other Parts Discussed in Thread: CC2640, CC2650

I want to implement CC2640 receive UART data by interrupt mode. How to do it.

My code is :

UART_Params_init(&SbpUartParams);

SbpUartParams.baudRate = 9600;
SbpUartParams.writeDataMode = UART_DATA_BINARY;
SbpUartParams.readMode = UART_MODE_CALLBACK;
SbpUartParams.readDataMode = UART_DATA_BINARY;
SbpUartParams.readReturnMode = UART_RETURN_FULL;
SbpUartParams.readEcho = UART_ECHO_OFF;
SbpUartParams.readCallback = readCallback;

SbpUartHandle = UART_open(CC2650_UART0, &SbpUartParams);

UART_read(SbpUartHandle, &input, 1);  //Enable  Rx

But in the "readCallback" I can't get the data.

How can I do it ? Is there any sample for this? thanks!

 

  • Hi,

    UART callback mode is supported. Please see the NPI implementation in HostTest project as a reference. Specifically, the npi_tl.c & npi_tl_uart.c files.

    Best wishes
  • Hi,

    Please you callback mode. Please see the UART configuration in mpi_tl_uart.c

    // Configure UART parameters.
    UART_Params_init(&params);
    params.baudRate = NPI_UART_BR;
    params.readDataMode = UART_DATA_BINARY;
    params.writeDataMode = UART_DATA_BINARY;
    params.dataLength = UART_LEN_8;
    params.stopBits = UART_STOP_ONE;
    params.readMode = UART_MODE_CALLBACK;
    params.writeMode = UART_MODE_CALLBACK;
    params.readEcho = UART_ECHO_OFF;

    params.readCallback = NPITLUART_readCallBack;
    params.writeCallback = NPITLUART_writeCallBack;

    // Open / power on the UART.
    uartHandle = UART_open(Board_UART, &params);

    Regards,
    Arun
  • Hi JXS,

    I added the npi_tl.c and the npi_tl_uart.c into the SimplePeripheral project.

    and called the function " NPITL_initTL(NULL,&readCallback,NULL);"

    I sent some data to the smartRF06 EVB, the function "readCallback" never run.

    Do I miss something? Thanks.
  • Hi Arun,

    I added the npi_tl.c and the npi_tl_uart.c into the SimplePeripheral project.

    and called the function " NPITL_initTL(NULL,&readCallback,NULL);"

    I sent some data to the smartRF06 EVB, the function "readCallback" never run.

    Do I miss something? Thanks.
  • hi,

    Are you getting a callback in NPITLUART_readCallBack? this function will be first called then your callBack should get called. This is working in HostTest Application. Can you check that?

    Regards,
    Arun
  • Hi, It couldn't run the NPITLUART_readCallBack function.
  • Hi Hark,

    Not sure why it is not working for you. Please make sure that the "Enable UART over XDS100v3" jumper is connected on the SmartRF06EB.

    Below is a tested example of UART in a standalone task receiving data into rxBuf, copying them over to txBuf in the read callback and echoing them back to the host.

    Regards,
    Svend

    #include "Board.h"
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Semaphore.h>
    #include <ti/drivers/PIN/PINCC26XX.h>
    #include <ti/drivers/UART.h>
    
    #include "string.h"
    
    
    #define TASK_STACK_SIZE 512
    #define TASK_PRI        1
    
    char        taskStack[TASK_STACK_SIZE];
    Task_Struct taskStruct;
    
    void taskFxn(UArg a0, UArg a1);
    
    
    #define BUFTYPE char
    #define PBUFTYPE char*
    #define BUFSIZE 1
    UART_Handle hUART;
    
    BUFTYPE rxBuf[BUFSIZE];
    BUFTYPE txBuf[BUFSIZE];
    
    
    Semaphore_Struct sem;
    Semaphore_Handle hSem;
    
    int main(void) {
    
      PIN_init(BoardGpioInitTable);
    
      Task_Params params;
      Task_Params_init(&params);
      params.priority = TASK_PRI;
      params.stackSize = TASK_STACK_SIZE;
      params.stack = taskStack;
    
      Task_construct(&taskStruct, taskFxn, &params, NULL);
    
      BIOS_start();
    }
    
    
    static void uartRxCb(UART_Handle handle, void *buf, size_t count) {
      //Copy rxBuf to txBuf
      memset(txBuf, 0, BUFSIZE);
      memcpy(txBuf, rxBuf, count);
      //Wake task to echo
      Semaphore_post(hSem);
    }
    
    void taskFxn(UArg a0, UArg a1) {
    
      UART_Params params;
      UART_Params_init(&params);
    
    
      params.readMode     = UART_MODE_CALLBACK;
      params.writeMode    = UART_MODE_BLOCKING;
      params.readCallback = uartRxCb;
      params.readEcho     = UART_ECHO_OFF; //Not needed on CC26XX implementation as not implemented
      params.baudRate     = 9600;
    
      hUART = UART_open(CC2650_UART0, &params);
    
      Semaphore_Params sParams;
      Semaphore_Params_init(&sParams);
      sParams.mode = Semaphore_Mode_BINARY;
    
      Semaphore_construct(&sem, 0, &sParams);
      hSem = Semaphore_handle(&sem);
    
      while(1) {
    
        UART_read(hUART, &rxBuf, sizeof(rxBuf)/sizeof(BUFTYPE));
    
        Semaphore_pend(hSem, BIOS_WAIT_FOREVER);
    
        UART_write(hUART, txBuf, sizeof(txBuf)/sizeof(BUFTYPE));
    
      }
    }
    

  • Hi,

    I wanted the device to respond to an interrupt upon receiving something on uart .May i know how to enable Uart in interrupt mode?
  • Hi svnebt

    Can u share ur code for uart communication with cc2650
  • TI -RTOS drivers are used for UART communication.

    You can find all the uart functions in :
    C:\ti\tirtos_simplelink_2_13_00_06\packages\ti\drivers\uart

    documentation can be found here :
    C:/ti/tirtos_simplelink_2_13_00_06/docs/doxygen/html/_u_a_r_t_8h.html

    TI-RTOS can be downloaded here :
    http://www.ti.com/tool/ti-rtos
  • Hii Svend I want to test my Smart RF06 UART so i want to send the DATA from one Smart RF 06 EVB to other Smart RF06 EVB through UART so could u please send me by sending the working code to perform UART operation please

    I have connected Gnd to GND and Tx to RX and RX to TX on the board.