完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本帖最后由 一只耳朵怪 于 2018-6-6 17:01 编辑
ti工程师您好 我有几个问题请教一下 1:TI的串口中断是用的回调,假如串口正在接收数据,这时我在主线程里发送数据会有什么问题吗? 2:串口的32字节缓冲是发送和独立共享的还是 发送就是发送的 接收就是接收的 ? 3:我用了最新的串口驱动,利用中断读数据,但是我测试发现中断是来一个数据中断一次,并且再次触发中断必须在中断里read一下,这种情况导致一个问题出现,就是我发送100个字节的时候一次发送完,后面我再打印接收的数据发现本来我发的是1234567890结果后面几个字节偶尔会间隔丢失,只会受到13579。 不知道是否有更好的例程!方便的话给我一份,谢谢, jnq123@qq.com |
|
相关推荐
6个回答
|
|
1. 没有问题
2.接受 发送是独立的FIFO缓冲,请看http://www.ti.com/lit/ug/swcu117h/swcu117h.pdf 19.2章 3, 是哪一个例子? Uartecho? 可修改接收长度 |
|
|
|
uuwufydsw 发表于 2018-6-6 10:57 您好工程师 感谢您的回答 串口接收发送丢失的情况 我发现是 波特率太高导致,我降低到19200 就很好了 |
|
|
|
uuwufydsw 发表于 2018-6-6 10:57 TI工程师您好 我在下面的测试发现 串口 我在及短的时间内发送数据,,会导致串口中断不再响应,,,感觉应该是 发满了 缓冲区,,,这时 如果 我想办法 1310的串口发送一个数据 那么串口就活了。。。 |
|
|
|
xianhaizhe 发表于 2018-6-6 11:23 极短时间是怎么做到呢?代码贴出来? |
|
|
|
TI工程师您好 我就是用下面这个代码做的,我用间隔10MS的时间发送100个字节,连续发送几次 就会死掉,然后等待多久也不会再次工作,但是无意中触发一下串口的发送,他又活了。。。 /* * Copyright (c) 2015, Texas Instruments Incorporated * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * ======== uartecho.c ======== */ /***** Includes *****/ #include "UartTask.h" /* XDCtools Header files */ //#include #include #include #include /* BIOS Header files */ #include #include #include #include #include /* TI-RTOS Header files */ #include #include /* Example/Board Header files */ #include "Board.h" #include #include extern time_rx_cs; //#include /***** Defines *****/ #define UART_TASK_STACK_SIZE 2048 #define UART_TASK_PRIORITY 2 //#define UART_EVENT_ALL 0xFFFFFFFF //#define UART_EVENT_PRINT 0x00000001 //add by barbara -- begin uint8_t len; ///length of RX'ed packet int8_t payload[128]; ///payload of RX'ed packet //add by barbara -- end #define UART_ACTIVITY_LED Board_LED4 /***** Variable declarations *****/ static Task_Params uartTaskParams; Task_Struct uartTask; /* not static so you can see in ROV */ static uint8_t uartTaskStack[UART_TASK_STACK_SIZE]; Event_Struct uartEvent; /* not static so you can see in ROV */ static Event_Handle uartEventHandle; /***** Prototypes *****/ static void uartTaskFunction(UArg arg0, UArg arg1); char a[10]; void Int_to_Ascii(uint16_t i); UART_Params uartParams; int RxBufPos = 0; int RxBufRead = 0; uint8_t Uart_TxBuf[UART_FIFO_FULL_SIZE]; int TxBufPos = 0; char Uart_TxTempBuf[120]; extern time_t t1; extern struct tm *ltm; extern char *curTime; extern int time_rx_cs; /***** Function definitions *****/ // Callback function void Uart_ReadCallback(UART_Handle handle, void *rxBuf, size_t size) [ // Copy bytes from RX buffer to TX buffer int i; UART_readCancel(handle); if((size<120)&&(size>0)) [ for (i = 0; i < size; i++) [ if(RxBufPos != UART_FIFO_FULL_SIZE ) [ Uart_RxBuf[RxBufPos] = ((uint8_t *)rxBuf); RxBufPos++; ] ] time_rx_cs=0; ] // UART_read(handle, uart_da_buf, 1); UART_read(uart, Uart_RxTempBuf, 1); /* for (i = 0; i < size; i++) [ if(RxBufPos != UART_FIFO_FULL_SIZE ) [ Uart_RxBuf[RxBufPos] = ((uint8_t *)rxBuf); RxBufPos++; ] else [ RxBufPos = 0; Uart_RxBuf[RxBufPos] = ((uint8_t *)rxBuf); RxBufPos++; ] ] */ //// // Echo the bytes received back to transmitter //Uart_TxBuf[0] = ((uint8_t *)rxBuf)[0]; // Start another read, with size the same as it was during first call to UART_read() // if(Uart_RxBuf[RxBufPos-1] == 'Z') [ // UART_write(uart, "Send", 4); //post event to rf // Uart_PostEvent(UART_EVENT_RECEIVED); ] /**/ ] // Callback function void Uart_WriteCallback(UART_Handle handle, void *txBuf, size_t size) [ // Start another read, with size the same as it was during first call to UART_read() UART_read(handle, Uart_RxTempBuf, 1); ] void UartTask_init() [ /* Create event used internally for state changes */ Event_Params eventParam; Event_Params_init(&eventParam); Event_construct(&uartEvent, &eventParam); uartEventHandle = Event_handle(&uartEvent); /* Create the node task */ Task_Params_init(&uartTaskParams); uartTaskParams.stackSize = UART_TASK_STACK_SIZE; uartTaskParams.priority = UART_TASK_PRIORITY; uartTaskParams.stack = &uartTaskStack; Task_construct(&uartTask, (Task_FuncPtr)uartTaskFunction, &uartTaskParams, NULL); /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.readMode = UART_MODE_CALLBACK; uartParams.readCallback = Uart_ReadCallback; uartParams.writeCallback = Uart_WriteCallback; uartParams.writeMode = UART_MODE_CALLBACK; uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 57600; uart = UART_open(Board_UART0, &uartParams); UART_control(uart, UARTCC26XX_CMD_RETURN_PARTIAL_ENABLE, NULL); if (uart == NULL) [ System_abort("Error opening the UART"); ] //PIN_setOutputValue(ledPinHandle, Board_LED2, 1); UART_write(uart, "", 0); ] extern void rx_exit(void); /* * ======== echoFxn ======== * Task for this function is created statically. See the project's .cfg file. */ static void uartTaskFunction(UArg arg0, UArg arg1) [ UART_read(uart, Uart_RxTempBuf, 1); /* Loop forever echoing */ while (1) [ /* Wait for event */ uint32_t events = Event_pend(uartEventHandle, 0, UART_EVENT_ALL, BIOS_WAIT_FOREVER); //If new ADC value, send this data if(events & UART_EVENT_PRINT) [ if((len<120)&&(len>0)) UART_write(uart, payload, len); ] if(events & UART_EVENT_RECEIVED) [ // UART_write(uart, Uart_RxBuf, RxBufPos); xxx=RxBufPos; RxBufPos = 0; ] if(events & UART_EVENT_FORWARD) [ ] ] ] /* Post event */ void Uart_PostEvent(uint32_t event) [ Event_post(uartEventHandle, event); ] void Int_to_Ascii(uint16_t i) [ int n; for(n=9;n>0;n--)[ a[n]=(i%10); if(a[n]!=0) a[n]+=0x30; else a[n]=0; i/=10; ] ] |
|
|
|
运行全双工的,可以发的
|
|
|
|
只有小组成员才能发言,加入小组>>
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
709 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
618 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1080 浏览 1 评论
774 浏览 0 评论
普中科技F28335开发板每次上电复位后数码管都会显示,如何熄灭它?
537 浏览 1 评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
189浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
147浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
16浏览 13评论
在使用3254进行录音的时候出现一个奇怪的现象,右声道有吱吱声,请教一下,是否是什么寄存器设置存在问题?
138浏览 13评论
TLV320芯片内部自带数字滤波功能,请问linein进来的模拟信号是否是先经过ADC的超采样?
132浏览 12评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-4 06:02 , Processed in 0.863607 second(s), Total 86, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号