Other Parts Discussed in Thread:CC3220SF
SDK:simplelink_cc32xx_sdk_4_20_00_07 开发板:官方CC3220SF
起步例程:uartecho
在我实验完uartecho后,我尝试着自己写一个uart驱动,使用的回调模式,但奇怪的是,无论我发多少次数据,读回调中断始终没有触发,逻辑分析仪上可以看到TX发送的数据,为此我有些问题想请教:
1. 发送数据是否有数据格式?垃圾数据难道不能发送成功吗?如果有标准格式,那会是什么样的呢?
2. 我查看相关文档的时候,我注意到当FIFO被填满的时候中断也会触发,但实际情况是无论我发送多少次数据我都没办法触发读回调
3. 我的初始化配置是否正确?我的目的是想让两块CC3220SF互相通过uart通信。(使用了UARTDMA)
4. 感激不尽,望能一一解答,下面附上我的代码
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_BYTES30// Maximum RX bytes to receive in one go #define MAX_NUM_TX_BYTES30// 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 bytesif (size == wantedRxBytes) {// Copy bytes from RX buffer to TX bufferfor ( i = 0; i < size; i++)txBuf[i] = ((uint8_t*)rxBuf)[i];// Echo the bytes received back to transmitterUART_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) {//charinput;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) {} }
Kevin Qiu1:
数据格式没有严格要求,正常数据可以收发,你所说的垃圾数据具体指的是什么
串口初始化配置没有问题
,
user6359397:
如果数据格式没有严格要求,那就不必追究垃圾数据了,我现在是连任何数据都无法接收,我不明白到底问题出在哪,我该如何下手排查
,
Kevin Qiu1:
两块板子的线是怎么连接的,用的是哪个uart,接收端串口是否配置正确 e2e.ti.com/…/869335
,
Kevin Qiu1:
两块板子进行串口通信要确保发送的板子是否正常发出数据,连接时要共地,串口参数设置要相同
可以通过串口助手先分别测试发送端和接收端是否正常,然后再将两块板子连起来测试
,
user6359397:
谢谢你的建议,我已经完成了这项目标,我更换了uart引脚后通信就能成功了。十分感谢
,
Kevin Qiu1:
问题解决就好