TI中文支持网
TI专业的中文技术问题搜集分享网站

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);
        }
    }
}

Kevin Qiu1:

/*!*@briefFunction that reads data from a UART with interrupt enabled.**%UART_read() reads data from a UART controller. The destination is specified*by \a buffer and the number of bytes to read is given by \a size.**In #UART_MODE_BLOCKING, %UART_read() blocks task execution until all*the data in buffer has been read.**In #UART_MODE_CALLBACK, %UART_read() does not block task execution.*Instead, a callback function specified by UART_Params::readCallback*is called when the transfer is finished.*The callback function can occur in the caller's context or in HWI or SWI*context, depending on the device-specific implementation.*An unfinished asynchronous read operation must always be canceled using*UART_readCancel() before calling UART_close().**%UART_read() is mutually exclusive to UART_readPolling(). For an opened*UART peripheral, either %UART_read() or UART_readPolling() can be used,*but not both.**@sa UART_readPolling()**@paramhandleA #UART_Handle returned by UART_open()**@parambufferA pointer to an empty buffer to which*received data should be written**@paramsizeThe number of bytes to be written into buffer**@return Returns the number of bytes that have been read from the UART,*#UART_STATUS_ERROR on an error.*/
extern int_fast32_t UART_read(UART_Handle handle, void *buffer, size_t size);

单步运行看程序是否可以执行到UART_read部分,另外看下数据是否已经发出

,

Lease:

数据已经发出了,Rx上也有数据,程序页执行到了uart_read部分。

逻辑分析仪看到的数据如下

程序运到uart_read时程序卡在汇编语言阶段

,

Kevin Qiu1:

看起来是没有使能中断

,

Lease:

使用的是sysconfig配置Rx和Tx引脚,并没有看到引脚配置使能中断,我需要例外定义uart引脚使能中断吗?该如何使能中断?

,

Kevin Qiu1:

看下C:/ti/simplelink_cc32xx_sdk_4_20_00_07/docs/tidrivers/doxygen/html/_u_a_r_t_8h.html中的用法示例

,

Lease:

我测试过了uart的两个例子都实验够了,能够从终端读取数据数据,并在终端显示。
但是,如果我使用另外一块CC3220SF开发版发送数据,接收端还是不能够读取到数据。

,

Lease:

我发现uart _read只能接收我在terminal中输入的数据,如果我给Rx添加输入波形,发现uart_read函数没有响应

,

Kevin Qiu1:

用两块板子一个发送另一个接收可以收到数据吗

,

Lease:

如果是终端输入的话,可以接收到数据。
我现在遇到的问题跟这个帖子是一样的。
e2echina.ti.com/…/130825

,

Lease:

e2e.ti.com/…/785504
e2echina.ti.com/…/367962
但并没有解决我现在遇到的问题

,

Kevin Qiu1:

直接发送一组数据,查看另一设备是否能收到

,

Lease:

直接发送数据也接收不到数据。

,

Kevin Qiu1:

已在https://e2echina.ti.com/question_answer/wireless_connectivity/wifi/f/105/t/194355

回复

赞(0)
未经允许不得转载:TI中文支持网 » uart_read 读取不到数据?
分享到: 更多 (0)