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.

uart_read 读取不到数据?

Other Parts Discussed in Thread: CC3220SF, SYSCONFIG

我使用CC3220SF中ti驱动uartecho例程。自己修改了sysconfig中uart驱动的Rx和Tx引脚。然后我创建了Txbuf和Rxbuf两个缓冲区,并用杜邦线把RX引脚与Tx引脚相连。以此实现自发自收的目的。

1.我使用uart_write()发送数据给Rx引脚,发现uart_read的始终不能读取到数据?

代码如下:

/*
 *  ======== uartecho.c ========
 */
#include <stdint.h>
#include <stddef.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include "UART.h"

/* Driver configuration */
#include "ti_drivers_config.h"
#include "unistd.h"
/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    UART_Handle uart;
    UART_Handle uart1;
    UART_Params uartParams;
    uint8_t TX_data[8] = {0x01,0x03,0x00,0x64,0x00,0x01,0xc5,0xd5};
    uint8_t RX_data[8] = {0};
    uint8_t count = 0;
    /* Call driver init functions */
    GPIO_init();
    UART_init();

    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* Turn on user LED */
    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);


    /* Create a UART with data processing off. */
     UART_Params_init(&uartParams);
     uartParams.readMode = UART_MODE_BLOCKING;
     uartParams.writeMode = UART_MODE_BLOCKING;
//     uartParams.writeTimeout = 1000;
     uartParams.writeDataMode = UART_DATA_BINARY;
     uartParams.readDataMode = UART_DATA_BINARY;
     uartParams.readReturnMode = UART_RETURN_FULL;
     uartParams.readTimeout = 1000;
     uartParams.baudRate = 9600;
     uartParams.dataLength = UART_LEN_8;
     uartParams.stopBits = UART_STOP_ONE;
     uartParams.parityType = UART_PAR_NONE;
     uartParams.readEcho = UART_ECHO_OFF;
    uart = UART_open(CONFIG_UART_0, &uartParams);

    if (uart == NULL) {
        /* UART_open() failed */
        while (1);
    }

    uart1 = UART_open(CONFIG_UART_1, &uartParams);
    if (uart1 == NULL) {
            /* UART_open() failed */
            while (1);
     }

    /* Loop forever echoing */
    while (1) {
        UART_write(uart1, TX_data, 8);
        count =  UART_read(uart1, RX_data, 8);
        if(count > 0)
        {
            GPIO_toggle(CONFIG_GPIO_LED_0);
        }
    }
}