串行传输 UART 延迟
我目前有一个嵌入式设备通过串行端口连接到 PC。我在电脑上接收数据时遇到问题。当我使用 PCI 串口卡时,我能够立即接收数据(没有延迟)。当我使用 USB 转串口插头或内置串口的主板时,我必须延迟读取数据(32 字节数据包为 40 毫秒)。
我能发现的硬件之间的唯一区别是 UART。 PCI卡使用16650,插头/主板使用标准16550A。 PCI卡设置为28字节中断,插头设置为14字节中断。
我以 56700 波特率连接(如果这有帮助的话)。
延迟占占空比的大部分,并且确实增加了传输时间。 (10 分钟换乘 vs 1 小时换乘)。
有人能解释一下为什么我必须对插头/主板使用延迟吗?谁能提出一个可能的解决方案来最小化或消除这种延迟?
I currently have an embedded device connected to a PC through a serial port. I am having trouble with receiving data on the PC. When I use my PCI serial port card I am able to receive data right away (no delays). When I use my USB-To-Serial plug or the motherboards built in serial port I have to delay reading data (40ms for 32byte packets).
The only difference I can find between the hardware is the UART. The PCI card uses a 16650 and the plug/motherboard uses a standard 16550A. The PCI card is set to interrupt at 28 bytes and the plug is set to interrupt at 14 bytes.
I am connected at 56700 Baud (if this helps).
The delay becomes the majority of the duty cycle and really increases transfer time. (10min transfer vs 1 hour transfer).
Does anyone have an explanation for why I have to use a delay with the plug/motherboard? Can anyone suggest a possible solution to minimizing or removing this delay?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能会发现不同的 USB 串行转换器会产生不同的结果。我们发现 FTDI 非常适合与嵌入式设备通信。一些转换器似乎会长时间缓冲数据和/或将其分段。
我从未见过主板连接出现问题 - 不确定那里发生了什么!可以更改主板串口的中断点吗?
You'll probably find that different USB-Serial converters produce different results. We've found that the FTDI ones work well for talking with embedded devices. Some converters seem to buffer the data for a long time and/or fragment it.
I've never seen a problem with a motherboard connection - not sure what is going on there! Can you change the interrupt point for the motherboard serial port?
我有一个串口转USB转换器。当我将它连接到我的分线盒并创建环回时,我能够以接近 1Mbps 的速度发送/接收,没有任何问题。串行端口发送可以转换为 ascii 数据的二进制数据。
使用 .Net,我将软件设置为在每个字节上触发一个事件 (ReceivedBytesThreshold=1),但这并不意味着它会发生。
I have a serial to usb converter. When I hook it up to my breakout box and create a loopback I am able to send / receive at close to 1Mbps without problems. The serial port sends binary data that may be translated into ascii data.
Using .Net I set my software to fire an event on every byte (ReceivedBytesThreshold=1), though that doesn't mean it will.
Linux 为串行驱动程序提供了一个 ASYNC_LOW_LATENCY 标志,这可能会有所帮助。无论您使用什么驱动程序,都可能有类似的东西。
但是,延迟不会对批量传输造成影响。它应该在传输开始时增加 40 毫秒,仅此而已,这就是为什么驾驶员一开始就不用担心的原因。我建议重构您的传输协议以使用 滑动窗口协议,窗口大小约为如果您以该波特率和延迟处理 32 字节数据包,则为 100 个数据包。换句话说,如果您还没有收到 100 个数据包之前发送的数据包的 ACK,您只想停止传输。
Linux has an ASYNC_LOW_LATENCY flag for the serial driver that may help. Whatever driver you're using may have something similar.
However, latency shouldn't make a difference on a bulk transfer. It should add 40 ms at the very start of the transfer and that's it, which is why drivers don't worry about it in the first place. I would recommend refactoring your transfer protocol to use a sliding window protocol, with a window size of around 100 packets, if you are doing 32-byte packets at that baud rate and latency. In other words, you only want to stop transmitting if you haven't received an ACK for the packet you sent 100 packets ago.