打印
[CC3200]

CC3220SF UART读取中断触发失败

[复制链接]
700|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
exiao2011|  楼主 | 2020-10-21 20:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
SDK:simplelink_cc32xx_sdk_4_20_00_07                            开发板:官方CC3220SF
起步例程:uartecho
在我实验完uartecho后,我尝试着自己写一个uart驱动,使用的回调模式,但奇怪的是,无论我发多少次数据,读回调中断始终没有触发,逻辑分析仪上可以看到TX发送的数据,为此我有些问题想请教:
1. 发送数据是否有数据格式?垃圾数据难道不能发送成功吗?如果有标准格式,那会是什么样的呢?
2. 我查看相关文档的时候,我注意到当FIFO被填满的时候中断也会触发,但实际情况是无论我发送多少次数据我都没办法触发读回调
3. 我的初始化配置是否正确?我的目的是想让两块CC3220SF互相通过uart通信。(使用了UARTDMA)
4. 感激不尽,望能一一解答,下面附上我的代码
[size=1em][color=white !important]
[size=1em]?

static const UARTCC32XXDMA_HWAttrsV1 uartCC32XXHWAttrs0 = {
    .baseAddr           = UART0_BASE,
    .intNum             = INT_UART0,
    .intPriority        = (~0),
    .flowControl        = UARTCC32XXDMA_FLOWCTRL_NONE,
    .rxChannelIndex     = UDMA_CH8_UARTA0_RX,
    .txChannelIndex     = UDMA_CH9_UARTA0_TX,
    .rxPin              = UARTCC32XXDMA_PIN_45_UART0_RX,
    .txPin              = UARTCC32XXDMA_PIN_62_UART0_TX,
    .ctsPin             = UARTCC32XXDMA_PIN_UNASSIGNED,
    .rtsPin             = UARTCC32XXDMA_PIN_UNASSIGNED,
    .errorFxn           = NULL
  };

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

/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/UART.h>
#include <ti/posix/ccs/unistd.h>
/* Driver configuration */
#include "ti_drivers_config.h"

#define MAX_NUM_RX_BYTES    30   // Maximum RX bytes to receive in one go
#define MAX_NUM_TX_BYTES    30   // Maximum TX bytes to send in one go
uint32_t wantedRxBytes;            // Number of bytes received so far
uint8_t rxBuf[MAX_NUM_RX_BYTES];   // Receive buffer
uint8_t txBuf[MAX_NUM_TX_BYTES];   // Transmit buffer


UART_Handle uart;
int32_t readCount;
uint8_t sendbuffer[20] = {0x40,0x10,0x40,0x10,0x40,0x10,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x80,0x20,0x20,0x20};
uint8_t recvicebuffer[16];
int c;
size_t i ;
void gpioButtonFxn0(uint_least8_t index)
{
    UART_write(uart, &sendbuffer, wantedRxBytes);
}
// Write callback function
static void writeCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    // Do nothing
}
// Read callback function
static void readCallback(UART_Handle handle, void *rxBuf, size_t size)
{
    GPIO_toggle(CONFIG_GPIO_LED_0);
    // 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];
       // 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, wantedRxBytes);
       GPIO_toggle(CONFIG_GPIO_LED_1);
    }
    else {
        // Handle error or call to UART_readCancel()
    }
}




/*
*  ======== mainThread ========
*/
void *mainThread(void *arg0)
{
    //char        input;
    const char  echoPrompt[] = "Echoing characters:\r\n";
    UART_Params uartParams;

    /* 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);
    GPIO_setConfig(CONFIG_GPIO_LED_1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(CONFIG_BUTTON_0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);


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

    /* Install Button callback */
    GPIO_setCallback(CONFIG_BUTTON_0, gpioButtonFxn0);
    /* Enable interrupts */
    GPIO_enableInt(CONFIG_BUTTON_0);
    /* 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.baudRate = 115200;

    uart = UART_open(CONFIG_UART_0, &uartParams);
    if (uart == NULL) {
        /* UART_open() failed */
        while (1);
    }
    UART_write(uart, echoPrompt, sizeof(echoPrompt));
    wantedRxBytes = 16;
    int rxBytes = UART_read(uart, rxBuf, wantedRxBytes);


   // UART_write(uart, echoPrompt, sizeof(echoPrompt));

    /* Loop forever echoing */
    while (1) {
    }
}







使用特权

评论回复

相关帖子

沙发
dirtwillfly| | 2020-10-21 21:16 | 只看该作者

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

14

主题

141

帖子

0

粉丝