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.

CC1310一直不能进入串口读回调函数!利用回调函数想实现类似串口接收中断的功能!

CC1310一直无法进入串口读回调函数readCallback(UART_Handle uarthandle, void *rxBuf, size_t size),利用回调函数想实现类似串口接收中断的功能,代码如下:

unsigned char  lhg3[] = "lhg3";
static void readCallback(UART_Handle uarthandle, void *rxBuf, size_t size)
{
size_t i = 0;

rxBytes = UART_read(uarthandle, rxBuf, wantedRxBytes);
// Make sure we received all expected bytes
if (size == wantedRxBytes) {
// Copy bytes from RX buffer to TX buffer
for(i = 0; i < size; i++)
txBuf[i] = ((uint8_t*)rxBuf)[i];
uart_receive_flag=1;

}
else {
// uarthandle error or call to UART_readCancel()
}
}
// Write callback function
static void writeCallback(UART_Handle uarthandle, void *rxBuf, size_t size)
{
// Do nothing
}


/*
* ======== mainThread ========
*/
void *uart_task(void *arg0)
{
/* Create a UART with data processing off. */
UART_Params_init(&uartparams);
uartparams.writeMode = UART_MODE_CALLBACK;
uartparams.writeDataMode = UART_DATA_BINARY;
uartparams.writeCallback = writeCallback;
uartparams.readMode = UART_MODE_CALLBACK;
uartparams.readDataMode = UART_DATA_BINARY;
uartparams.readCallback = readCallback;
uartparams.readReturnMode = UART_RETURN_NEWLINE;//UART_RETURN_FULL UART_RETURN_NEWLINE
uartparams.readEcho = UART_ECHO_OFF;
uartparams.baudRate = 115200;


// Open the UART and initiate the first read
uarthandle = UART_open(Board_UART0, &uartparams);

UART_write(uarthandle, "\r\nUart_task begin......\r\n", 25);
/* Loop forever echoing */
while (1) {

if(uart_receive_flag==1 ){
uart_receive_flag=0;

UART_write(uarthandle,lhg3,sizeof(lhg3));
}
}
}


/*
* ======== uart_taskint ========
*/
void uart_taskint(void){

Task_Params_init(&taskParams);
taskParams.stackSize = uart_THREADSTACKSIZE;
taskParams.stack = &uart_taskStack;
taskParams.priority = 2;
Task_construct(&uart_taskStruct, uart_task, &taskParams, NULL);


}

上述程序串口可以输出Uart_task begin......,最后一直在while (1) 循环,一直不能进入串口接收回调函数readCallback,uart_receive_flag无法置1。已经困扰几天找不原因,请各位老师指点。用的板子是官方CC1310 LaunchPad