完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,社区,最近我遇到了一个问题,如何检测UART是否准备好了它的传输。这并不像乍看起来那么容易。UART有多达3个区域,其中要传输的数据是:第一缓冲器(当在模块配置中定义)第二FIFO,4字节深度保存未发送数据,从中断例程第三中的缓冲器中提供字节,通常被遗忘,Tx移位寄存器,实际上持有。传输字节
获取缓冲区是否已经空的信息的API是UARTHGETGETXBuffResiSe(),它不返回名称所暗示的大小,而是返回缓冲区中使用的字节数。因此返回值为0(零)表示空缓冲区。 为了看看FIFO状态,我们有API UARTHARETCTXSTATUSER(),它不仅指示一个空的FIFO和一个位掩码 UARTHXTXYSTSH FIFOSY空,但指示TX移位寄存器的完整传输与掩蔽名为UARTHARTXYSTSSO完成。遗憾的是,当用API读取时,该位被重置。 当编写一个函数返回UART的忙状态时,我们必须考虑以下事实:缓冲器必须是空的FIFO必须是空的传输必须完成。 问题是,当查看“传输必须完成”时,API将状态设置为“传输不完全”,这会在下一个繁忙的UART返回“忙”的情况下回答,而当等待“准备”UART时,这个答案会导致无限循环。 因此,给出正确结果的函数有点复杂。我在这篇文章中附上一篇。 什么时候需要这个功能?传输数据时的所有管理都是由提供的UART例程来处理的,所以不需要。但是当你必须停止UART的时候 原因(主要是进入睡眠模式),你必须确保所有的通信。 这里的功能是: Uti8UARTHOLL(空隙){UTIN STS;静态UIT8 FILSTSTIMECTORACE= TRUE;Y定义忙1 / /只为了更好地阅读(我希望) St= UARTHEADTXXSTATUS();如果(!)((uart_gettxbuffersize() = = 0)&;&;(STS &;uart_tx_sts_fifo_empty)))/ /串口缓冲区是空的吗?{ firsttimecalled = false;返回忙;/ /缓冲器不空,返回“忙”}其他/ / UART缓冲区是空的,但最后一个字节可以转移目前{ if(STS &;uart_tx_sts_complete)/ /转移完成?位叫uart_readtxstatus() { firsttimecalled =真正的复位;/ /是的,我们做的回报!忙;}其他/ /转移没有完成或叫后第一时间!忙返回{if(第一次调用)返回!忙;返回忙;}{undf繁忙} 玩得开心鲍伯 以上来自于百度翻译 以下为原文 Hi Community, lately I came over the question how to detect if an UART is ready with its transmission. This is not as easy as it seems as first sight. An UART has up to 3 areas where the data to be transmitted is stored: 1st The buffer (when defined in the module configuration) 2nd The FIFO, 4 bytes deep holding untransmitted data, fed with bytes from Buffer in the interrupt routine 3rd Often forgotten, the Tx-shift-register, holding the actually transmitted byte An API to get information whether the buffer is already empty is UART_GetTxBufferSize() which does not return the size as the name would suggest, but the number of used bytes in the buffer. Thus a returned value of 0 (zero) indicates an empty buffer. To have a look at the FIFO state we have the API UART_ReadTxStatus() which not only indicates an empty FIFO with a bit-mask named UART_TX_STS_FIFO_EMPTY but indicates a complete transmission of the tx-shift-register with a mask named UART_TX_STS_COMPLETE. Unfortunately this bit is reset when read with the API. When writing a function to return the busy state of an UART we have to consider following facts: Buffer must be empty FIFO must be empty Transfer must be complete. The problem is, when looking at "Transfer must be complete" the API sets the state to "Transfer NOT complete" which would at a next questioning for a busy UART return "Busy" and this answer can lead into an infinite loop when waiting for a "Ready" UART. So, a function to give a correct result is a bit complicated. I append one to this post. When is the function needed? All the management when transfering data is handled by the supplied UART-routines, so there is no need. But when you have to stop the UART for any reason (mostly to enter sleep mode) you must be sure that all communication is made. Here is the function: uint8 UART_Busy(void) { uint8 STS; static uint8 FirstTimeCalled = TRUE; #define Busy 1 // Just for better readabiliy (I hope) STS = UART_ReadTxStatus(); if (!((UART_GetTxBufferSize() == 0) && (STS & UART_TX_STS_FIFO_EMPTY))) // Are the UART buffers empty? { FirstTimeCalled = FALSE; return Busy; // Buffers NOT empty, return "Busy" } else // UART buffers empty, but last byte may be transfered currently { if (STS & UART_TX_STS_COMPLETE) // Is Transfer completed? Bit was reset with call to UART_ReadTxStatus() { FirstTimeCalled = TRUE; // Yes, we are done return !Busy; } else // Transfer not completed or called the first time after a !Busy returned { if (FirstTimeCalled) return !Busy; return Busy; } } #undef Busy } Have fun Bob |
|
相关推荐
6个回答
|
|
鲍伯,这是有价值的信息。这对sheing与其他社区的感谢。
以上来自于百度翻译 以下为原文 Bob, this is valuable information. Thanks for sheing this with the rest of the community. |
|
|
|
谢谢你,鲍伯!看来,程序需要调用之间的一个微小的延迟。我把cydelayus(0)-这就足够了,而(uart_busy()){ CyDelayUs(0);};不幸的是,我无法改变这一psoc4 scb-uart((4年过去了…这么快()
斯巴达 32.5 K 以上来自于百度翻译 以下为原文 Thank you, Bob! It seems the program requires a tiny delay between calls. I put CyDelayUs (0) - that was enough: while(UART_Busy()) { CyDelayUs(0); }; Unfortunately I was unable to change it for a PSoC4 SCB-UART (( 4 years have passed... so quickly((
|
|
|
|
这应该被纳入模块数据表。偶数
睡眠AP注意到。 只是说说而已。 问候,Dana。 以上来自于百度翻译 以下为原文 This should get incorporated into module datasheet. Even sleep ap notes. Just sayin. Regards, Dana. |
|
|
|
|
|
|
|
有趣的是,它花了三年的人挖出来后!
很高兴当我帮助的人,感谢评审和改进! 我同意Dana的观点,这个问题应该至少提到在sleep() API的UART。 鲍勃 以上来自于百度翻译 以下为原文 Interestingly it took three years since someone dug out that post! Glad when I have helped someone and thanks for reviewing and improving! I agree with Dana that this problem should be at least mentioned in the Sleep() API of the UART. Bob |
|
|
|
鲍伯,提出一个案子来修改文件。
问候,Dana。 以上来自于百度翻译 以下为原文 Bob, file a CASE to get the docs modified. Regards, Dana. |
|
|
|
只有小组成员才能发言,加入小组>>
750个成员聚集在这个小组
加入小组2062 浏览 1 评论
1818 浏览 1 评论
3628 浏览 1 评论
请问可以直接使用来自FX2LP固件的端点向主机FIFO写入数据吗?
1757 浏览 6 评论
1504 浏览 1 评论
CY8C4025LQI在程序中调用函数,通过示波器观察SCL引脚波形,无法将pin0.4(SCL)下拉是什么原因导致?
491浏览 2评论
CYUSB3065焊接到USB3.0 TYPE-B口的焊接触点就无法使用是什么原因导致的?
347浏览 2评论
CX3连接Camera修改分辨率之后,播放器无法播出camera的画面怎么解决?
407浏览 2评论
352浏览 2评论
使用stm32+cyw43438 wifi驱动whd,WHD驱动固件加载失败的原因?
844浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-14 13:18 , Processed in 1.006202 second(s), Total 89, Slave 72 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号