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 UART readcallback doesn't work, why?

Other Parts Discussed in Thread: CC2640

Hi,

I'm new to cc2640, right now I'm working on the UART reading function. I've initiated it and opened it with the function UART_Open(), and then I use UART_read() but can get nothing. I print message inner the readcallback function, but I find that this function doesn't work. Please help. Thanks!

I copy the code here, please check:

 // Configure UART parameters.
 UART_Params_init(&params);
 params.baudRate = 115200;
 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.readReturnMode = UART_RETURN_FULL;//UART_RETURN_NEWLINE;//UART_RETURN_FULL;
 params.readEcho = UART_ECHO_OFF;
 params.readTimeout = BIOS_WAIT_FOREVER;
#if (UART_CALL_BACK ==1)
 params.readCallback = Uart_ReadCallback;
 params.writeCallback = Uart_WriteCallback;
#else
 params.readCallback = NULL;
 params.writeCallback = NULL;
#endif

 uartHandle = UART_open(Board_UART, &params);
 print_msg("UART open: Baudrate = %d \r\n", params.baudRate);
 
 UART_control(uartHandle, UARTCC26XX_RETURN_PARTIAL_ENABLE, NULL);
 int rxBytes = UART_read(uartHandle, Uart_RxBuf, UART_FIFO_FULL_SIZE);
 print_msg("#1 UART read %d bytes = %d \r\n", rxBytes);

-------------------------------------------------------------------------------------------------------------------------------

// Callback function
void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size)
{
 //dubug
 print_msg("#uart read callback \r\n");
 
 // Copy bytes from RX buffer to TX buffer
 for (size_t i = 0; i < size; i++) {
  Uart_TxBuf[i] = ((uint8_t *)rxBuf)[i];
 }

 // Echo the bytes received back to transmitter
 UART_write(handle, Uart_TxBuf, size);

 // Start another read, with size the same as it was during first call to UART_read()
 UART_read(handle, Uart_RxBuf, UART_FIFO_FULL_SIZE);

 //dubug
 PUTchar8x16(1<<1, 2, (unsigned char *)Uart_TxBuf, 0);
 print_msg("\r\n");
}

  • Hello,

    Welcome to BLE! Since you are new, I would suggest going through the UART examples on the TI BLE wiki: www.ti.com/ble-wiki
    These examples do use the UART in callback mode for read/write.

    Best wishes