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.

CC2650 使用Uart接收数据的

Other Parts Discussed in Thread: CC2650

使用CC2650的Uart接收数据,采用的是readCallback模式,每次接收UART_BUFFER_SIZE = 8个数据。

当发送方每次发送8个字节的数据时,可以正常接收。

但是当数据不足8个时,缓存在uart缓存区,而不进入readCallback函数,非要等到凑齐8个才进入callback函数。

怎么设置,能让收到不满8个数,比如4个数据后,1秒内,没有新数据的话,就调用Callback呢?

另外这个params.readTimeout = 1000;  起到什么作用?

还有UARTCC26XX_control(handle, UARTCC26XX_RETURN_PARTIAL_ENABLE, NULL); 起到什么作用?

源程序如下:

/* Initialize the UART */
UART_Params params;
UART_Params_init(&params);

params.writeDataMode = UART_DATA_BINARY; //串口接收数据不做处理
params.readDataMode = UART_DATA_BINARY; //串口发送数据不做处理
params.readReturnMode = UART_RETURN_FULL; //当串口数据
params.dataLength = UART_LEN_8; //串口数据位8
params.stopBits = UART_STOP_ONE; //串口停止位1
params.parityType = UART_PAR_NONE; //无校验
params.baudRate = 115200; //串口波特率115200

/* Configure write callback */
//uartParams.writeMode = UART_MODE_BLOCKING;
/* Configure read callback */
params.readMode = UART_MODE_CALLBACK; //Callback模式
//params.readTimeout = 1000; //UART_ReadTimeout;
params.readCallback = UART_readCallback;
params.readEcho = UART_ECHO_OFF; //串口不回显

handle = UART_open(Board_UART, &params);

//UARTCC26XX_control(handle, UARTCC26XX_RETURN_PARTIAL_ENABLE, NULL);

UART_read(handle, UART_rxBuf, UART_BUFFER_SIZE);//UART_BUFFER_SIZE = 8

//UART_readPolling(handle, UART_rxBuf, UART_BUFFER_SIZE);

  • 可以partial 接收:

    Basic Receive
    Receive 100 bytes over UART in UART_MODE_BLOCKING.
    
    UART_Handle handle;
    UART_Params params;
    uint8_t rxBuf[100];         // Receive buffer
    uint32_t timeoutUs = 5000;  // 5ms timeout, default timeout is no timeout (BIOS_WAIT_FOREVER)
    // Init UART and specify non-default parameters
    UART_Params_init(&params);
    params.baudRate      = 9600;
    params.writeDataMode = UART_DATA_BINARY;
    params.readTimeout   = timeoutUs / ClockP_tickPeriod; // Default tick period is 10us
    // Open the UART and do the read
    handle = UART_open(Board_UART, &params);
    int rxBytes = UART_read(handle, rxBuf, 100);
    Receive with Return Partial This use case will read in UART_MODE_BLOCKING until the wanted amount of bytes is received or until a started reception is inactive for a 32-bit period. This UART_read() call can also be used when unknown amount of bytes shall be read. Note: The partial return is also possible in UART_MODE_CALLBACK mode. UART_Handle handle; UART_Params params; uint8_t rxBuf[100]; // Receive buffer // Init UART and specify non-default parameters UART_Params_init(&params); params.baudRate = 9600; params.writeDataMode = UART_DATA_BINARY; // Open the UART and initiate the partial read handle = UART_open(Board_UART, &params); // Enable RETURN_PARTIAL UART_control(handle, UARTCC26X0_CMD_RETURN_PARTIAL_ENABLE, NULL); // Begin read int rxBytes = UART_read(handle, rxBuf, 100));

  • 完美!戳中要害!