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

CC2642R: cc2642串口配置相关问题请教

Part Number:CC2642ROther Parts Discussed in Thread:SYSCONFIG, LAUNCHXL-CC26X2R1

我在使用ccs的配置工具配置完串口1时并未找到波特率和回调函数相关的配置,同时想问串口如果初始化相关的函数名称是什么.

望解答Rose

Galaxy Yue:

你好,

1.波特率的配置

https://e2echina.ti.com/support/wireless-connectivity/bluetooth/f/bluetooth-forum/201641/cc2642-syscfg-uart

2.是要用sysconfig配置回调函数吗?哪个函数

3.

UART_init() 的function描述在如下link中

https://software-dl.ti.com/simplelink/esd/simplelink_cc2640r2_sdk/2.20.00.49/exports/docs/tidrivers/doxygen/html/_u_a_r_t_8h.html#ab60a36f7295d704926120d22f806dcd1

// Import the UART driver definitions
#include <ti/drivers/UART.h>
// One-time initialization of UART driver
UART_init();
// Initialize UART parameters
UART_Params params;
UART_Params_init(&params);
params.baudRate = 9600;
params.readMode = UART_MODE_BLOCKING;
params.writeMode = UART_MODE_BLOCKING;
params.readTimeout = UART_WAIT_FOREVER;
params.writeTimeout = UART_WAIT_FOREVER;

,

viys:

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

int uarttree = 0;

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // // Make sure we received all expected bytes
    // if (size == 16) {
    //     // Copy bytes from RX buffer to TX buffer
    //    for(size_t i = 0; i < size; i++)
    //        txBuf[i] = ((uint8_t*)rxBuf)[i];

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

    //    // Start another read, with size the same as it was during first call to
    //    // UART_read()
    //    UART_read(handle, rxBuf, 16);
    // }
    // else {
    //     // Handle error or call to UART_readCancel()
    // }
    uarttree ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

int uarttree = 0;

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // // Make sure we received all expected bytes
    // if (size == 16) {
    //     // Copy bytes from RX buffer to TX buffer
    //    for(size_t i = 0; i < size; i++)
    //        txBuf[i] = ((uint8_t*)rxBuf)[i];

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

    //    // Start another read, with size the same as it was during first call to
    //    // UART_read()
    //    UART_read(handle, rxBuf, 16);
    // }
    // else {
    //     // Handle error or call to UART_readCancel()
    // }
    uarttree ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

int uarttree = 0;

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // // Make sure we received all expected bytes
    // if (size == 16) {
    //     // Copy bytes from RX buffer to TX buffer
    //    for(size_t i = 0; i < size; i++)
    //        txBuf[i] = ((uint8_t*)rxBuf)[i];

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

    //    // Start another read, with size the same as it was during first call to
    //    // UART_read()
    //    UART_read(handle, rxBuf, 16);
    // }
    // else {
    //     // Handle error or call to UART_readCancel()
    // }
    uarttree ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

int uarttree = 0;

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // // Make sure we received all expected bytes
    // if (size == 16) {
    //     // Copy bytes from RX buffer to TX buffer
    //    for(size_t i = 0; i < size; i++)
    //        txBuf[i] = ((uint8_t*)rxBuf)[i];

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

    //    // Start another read, with size the same as it was during first call to
    //    // UART_read()
    //    UART_read(handle, rxBuf, 16);
    // }
    // else {
    //     // Handle error or call to UART_readCancel()
    // }
    uarttree ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

int uarttree = 0;

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // // Make sure we received all expected bytes
    // if (size == 16) {
    //     // Copy bytes from RX buffer to TX buffer
    //    for(size_t i = 0; i < size; i++)
    //        txBuf[i] = ((uint8_t*)rxBuf)[i];

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

    //    // Start another read, with size the same as it was during first call to
    //    // UART_read()
    //    UART_read(handle, rxBuf, 16);
    // }
    // else {
    //     // Handle error or call to UART_readCancel()
    // }
    uarttree ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

int uarttree = 0;

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // // Make sure we received all expected bytes
    // if (size == 16) {
    //     // Copy bytes from RX buffer to TX buffer
    //    for(size_t i = 0; i < size; i++)
    //        txBuf[i] = ((uint8_t*)rxBuf)[i];

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

    //    // Start another read, with size the same as it was during first call to
    //    // UART_read()
    //    UART_read(handle, rxBuf, 16);
    // }
    // else {
    //     // Handle error or call to UART_readCancel()
    // }
    uarttree ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

int uarttree = 0;

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // // Make sure we received all expected bytes
    // if (size == 16) {
    //     // Copy bytes from RX buffer to TX buffer
    //    for(size_t i = 0; i < size; i++)
    //        txBuf[i] = ((uint8_t*)rxBuf)[i];

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

    //    // Start another read, with size the same as it was during first call to
    //    // UART_read()
    //    UART_read(handle, rxBuf, 16);
    // }
    // else {
    //     // Handle error or call to UART_readCancel()
    // }
    uarttree ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

int uartTemp = 0;

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}

static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{

    uartTemp ++;
}

void fp_init(void)
{
    UART_Handle handle;
    UART_Params params;
   
    /* 相关串口初始化 */
    UART_init();
    UART_Params_init(&params);
    params.baudRate      = 115200;
    params.writeMode     = UART_MODE_CALLBACK;
    params.writeDataMode = UART_DATA_BINARY;
    params.writeCallback = writeCallback;
    params.readMode      = UART_MODE_CALLBACK;
    params.readDataMode  = UART_DATA_BINARY;
    params.readCallback  = readCallback;

    handle = UART_open(CONFIG_FP_UART, &params);
}

您好上述是我的代码,我在配置完串口后,通过串口助手给芯片发送消息,我在其中一个任务中不断查看uartTemp 的值,发现其一直为零,串口并未进入接收中断.

,

Galaxy Yue:

你好,

1.首先你需要检查你的串口引脚和串口助手是否正确连接,并且稳定

然后你的芯片的串口配置是否正常。

2.你可以把do nothing 添加打印语句进行调试

static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
     uartTemp++;
printf("Received data: %s\n",(char *)rxBuf);
}
以此来验证是否触发回调函数

3.请问你具体是要通过这个串口做什么事情?

,

viys:

这个串口连接传感器进行通讯

,

viys:

刚尝试了下,writeCallback和串口发送正常,串口中断依旧无反应

,

viys:

我需要硬件中断触发串口读取回调函数readCallback

,

Galaxy Yue:

1.你可以使用 PIN 驱动程序,

2.考虑在 GAP 角色处于活动状态时不要对 UART 使用blocking mode

 

,

Galaxy Yue:

需要一些时间,谢谢

,

viys:

我发现问题了,

 ,

DIO29作为RX引脚,通过串口助手给其发送消息该引脚一致为低电平,后将程序烧录到LAUNCHXL-CC26X2R1开发板中该引脚同样为低电平不变.

这是我串口中的引脚配置

,

Galaxy Yue:

好,有问题欢迎再来论坛交流

,

viys:

我更换rx引脚后,通过串口助手发送数据,逻辑分析仪查看RX引脚波形,发现全程依旧为低电平

,

Galaxy Yue:

你烧录的程序是哪个?

,

viys:

我烧录的程序是公司的代码,将该程序烧录至ti开发板上,对rx引脚输入高电平其并未变高

,

Galaxy Yue:

你的问题将在你新发的帖子合并回复,

https://e2echina.ti.com/support/wireless-connectivity/bluetooth/f/bluetooth-forum/802283/cc2642r-cc2642r1-rx

需要一些时间,谢谢。

赞(0)
未经允许不得转载:TI中文支持网 » CC2642R: cc2642串口配置相关问题请教
分享到: 更多 (0)

© 2024 TI中文支持网   网站地图 鲁ICP备2022002796号-1