简体   繁体   English

使用 FTDI 电缆不支持 RS485 通信

[英]RS485 communication not supported using FTDI cable

I'm trying to port a program, which communicates over RS485 half-duplex UART, to Raspberry Pi.我正在尝试将通过 RS485 半双工 UART 通信的程序移植到 Raspberry Pi。 Since Pi's built-in UARTs don't support the RS485 standard, I'm using the USB-RS485-WE-1800-BT FTDI cable .由于 Pi 的内置 UART 不支持 RS485 标准,我使用的是 USB-RS485-WE-1800-BT FTDI 电缆

When connected, I can confirm that the cable's FTDI chip shows up in dmesg , the ftdi_sio driver is loaded, and properly exposes the /dev/ttyUSB0 serial terminal to the rest of the system.连接后,我可以确认电缆的 FTDI 芯片出现在dmesg ,加载了ftdi_sio驱动程序,并正确地将/dev/ttyUSB0串行终端暴露给系统的其余部分。 However, when I attempt to enable RS485 mode from a simple C program:但是,当我尝试从一个简单的 C 程序启用 RS485 模式时:

struct serial_rs485 config = {
  .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND,
  .delay_rts_before_send = 0,
  .delay_rts_after_send = 0
};
if (ioctl(fd, TIOCSRS485, &config) < 0) {
    fprintf(stderr, "ioctl failed (%d): %s\n", errno, strerror(errno));
    exit(0);
}

... I get the following error: ...我收到以下错误:

ioctl failed (25): Inappropriate ioctl for device

Looking into a schematic, I realized that the FTDI cable internally uses 2 components:查看原理图,我意识到 FTDI 电缆内部使用 2 个组件:

  1. the FT232R chip, which is controlled by the ftdi_sio driver over USB and produces conventional serial output, and FT232R 芯片,由ftdi_sio驱动程序通过 USB 控制并产生常规串行输出,以及
  2. the ZT485EEN chip, which transforms conventional serial comms to RS485. ZT485EEN 芯片,将传统的串行通信转换为 RS485。

So, given that FT232R doesn't technically emit RS485, I understand why its driver complains when asked to enable RS485 mode.因此,鉴于 FT232R 在技术上不发出 RS485,我理解为什么当要求启用 RS485 模式时它的驱动程序会抱怨。 What it doesn't know, though, is that the second chip takes care of format conversion transparently.但是,它不知道的是,第二个芯片透明地处理格式转换。

Having researched this topic for a bit and read answers to a similar question , I'm now curious how to proceed.研究了这个话题并阅读了类似问题的答案,我现在很好奇如何继续。 Should I change the request ID in my ioctl() call to something else than TIOCSRS485 ?我应该将ioctl()调用中的请求 ID 更改为TIOCSRS485以外的其他TIOCSRS485吗? Should I remove the ioctl() call entirely?我应该完全删除ioctl()调用吗? And if I do that, how can RS485 flags and RTS delays be set?如果我这样做,如何设置 RS485 标志和 RTS 延迟? Finally, if this means that enabling RS485 mode is not required in this configuration, can the FTDI cable be bypassed entirely by using Raspberry Pi's built-in UARTs combined with a chip like ZT485EEN?最后,如果这意味着在此配置中不需要启用 RS485 模式,是否可以通过使用 Raspberry Pi 的内置 UART 与 ZT485EEN 之类的芯片组合来完全绕过 FTDI 电缆?

Should I change the request ID in my ioctl() call to something else than TIOCSRS485 ?我应该将ioctl()调用中的请求 ID 更改为TIOCSRS485以外的其他TIOCSRS485吗? Should I remove the ioctl() call entirely?我应该完全删除ioctl()调用吗?

Removing the ioctl() would be the appropriate thing to do in this case, as the serial converter is handling it entirely for you.在这种情况下,删除ioctl()将是合适的做法,因为串行转换器完全为您处理它。 As far as you are concerned, it is just a serial port that you read and write to.就您而言,它只是您读写的串行端口。

And if I do that, how can RS485 flags and RTS delays be set?如果我这样做,如何设置 RS485 标志和 RTS 延迟?

You can't set any flags or delay using the FTDI cable.您不能使用 FTDI 电缆设置任何标志或延迟。 However, since the data that comes out of the cable is already RS485, there's no need to set anything.但是,由于从电缆中出来的数据已经是 RS485,因此无需进行任何设置。 As long as whatever it is you're talking to is half-duplex(it does not talk at the same time as you do), this isn't an issue, and you can use it just like an RS232 cable.只要您正在通话的是半双工(它不会与您同时通话),这都不是问题,您可以像使用 RS232 电缆一样使用它。 This depends on your specific use-case though.不过,这取决于您的特定用例。 I have never encountered the need to have an RTS delay.我从未遇到过需要 RTS 延迟的情况。

Finally, if this means that enabling RS485 mode is not required in this configuration, can the FTDI cable be bypassed entirely by using Raspberry Pi's built-in UARTs combined with a chip like ZT485EEN?最后,如果这意味着在此配置中不需要启用 RS485 模式,是否可以通过使用 Raspberry Pi 的内置 UART 与 ZT485EEN 之类的芯片组合来完全绕过 FTDI 电缆?

Sure, you can do that.当然,你可以这样做。 There are also many different models of RS485 transcievers that you could use;您还可以使用许多不同型号的 RS485 收发器; Electronics.SE would the the place to ask for more information on that. Electronics.SE 将是询问更多信息的地方。 You may need to enable RS485 at that point with TIOCSRS485 , but that's going to be driver-dependent.此时您可能需要使用TIOCSRS485启用 RS485 ,但这将取决于驱动程序。 I don't know about the Pi, but at least on some Atmel chips that I have used before setting the RS485 mode sets a certain bit in the peripheral on the chip that automatically toggles the RTS pin to enable/disable the RS485 transciever;我不知道 Pi,但至少在我在设置 RS485 模式之前使用过的一些 Atmel 芯片上,在芯片上的外围设备中设置了某个位,该位会自动切换 RTS 引脚以启用/禁用 RS485 收发器; otherwise, Linux needs to toggle a GPIO in order to set the transciever into the correct state.否则,Linux 需要切换 GPIO 以将收发器设置为正确的状态。

Specifically on the FTDI, there are GPIOs that can be set that will turn on/off at appropriate times.特别是在 FTDI 上,可以设置在适当的时间打开/关闭的 GPIO。 One of these is the TXDEN signal, which controls the transciever for you automatically.其中之一是 TXDEN 信号,它会自动为您控制收发器。 Others are used for the Tx/Rx LEDs.其他用于 Tx/Rx LED。

There's no “rs485” mode.没有“rs485”模式。 Just forget about it and everything will be OK.忘记它,一切都会好起来的。 RS485 is just an electrical standard, and the ZT485 does the electrical translation from logic levels to differential signaling and back. RS485 只是一个电气标准,ZT485 负责从逻辑电平到差分信号的电气转换,然后再返回。 You could use that chip (or any equivalent) directly with the UART pins on the Raspberry PI: those are not RS232 nor RS485, just bare asynchronous logic level UART pins.您可以将该芯片(或任何等效的)直接与 Raspberry PI 上的 UART 引脚一起使用:它们既不是 RS232 也不是 RS485,只是裸异步逻辑电平 UART 引脚。 Your assertion that Raspberry PI “doesn't support” RS485 is meaningless: it doesn't support RS232 either, and it's not supposed to.您断言 Raspberry PI“不支持”RS485 是没有意义的:它也不支持 RS232,也不应该支持。 Those electrical standards require level translation/interface chips, and the “other side” is always the same: logic level asynchronous serial streams and control lines.这些电气标准需要电平转换/接口芯片,而“另一面”总是相同的:逻辑电平异步串行流和控制线。 The only “pitfall” is choosing the proper logic levels (3.3V be 5V - I don't offhand remember what does RPI support).唯一的“陷阱”是选择正确的逻辑电平(3.3V 是 5V - 我不记得 RPI 支持什么)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM