[SOLVED] Interfacing with RS485/422? port behind an optocoupler - Page 1
Forum section: electronics / beginners

author: Rjevski
author_rank: Unknown
timestamp: March 19, 2023, 07:10:41 pm
content: Edit: solved, seehttps://www.eevblog.com/forum/beginners/interfacing-with-rs485422-port-behind-an-optocoupler/msg4778474/#msg4778474Hello everyone,A long time ago I got my hands on a TCS John Huxley roulette wheel - it has built-in optical sensors that can detect the winning number and tracks the state of the game. My local casino has very similar units and they are able to drive displays that show the current winning number and the history.The roulette has 4 RJ45 ports as well as a DB-9 port replicated on either side (continuity checking shows every pin electrically connected with its counterpart on the other side, so I think it's purely there for convenience so you can plug devices on either side).The DB-9 port looks like a serial port and on the mainboard inside only pins 2-5 have traces, suggesting it is indeed a serial port, however I've been unable to get any output from it. Most likely it's waiting for some special magic packet and given the lack of documentation it's probably a lost cause. There is absolutely nothing on Google about it and the manufacturer isn't responding.The mainboard also had an unpopulated UART header which got me very excited (I was hoping there would be some sort of debug log I can get the winning number out of to replicate the real display) but no luck there either. No output at all common baud rates and mashing my keyboard into a serial terminal didn't elicit a response either.This only leaves the 4 RJ45 ports. They are definitely not ethernet, and looking at the board only the first 4 pins are soldered. The board has ST485EB chips above each port, suggesting it's RS485. I suspect there are also optocouplers on those ports.Measuring between pin 1-2 in diode mode I find a 0.6V drop one way and 2.6V the other way, suggesting it's a diode?Measuring between pins 3-4 in diode mode I get 0.175V drop regardless of polarity.Measuring between pins 3-4 I get 120ohms in resistance mode.Measuring between pins 2 to 3 or 4 gives me 56k ohms.Measuring between pins 1 and 2 gives me a very high resistance in the order of a couple megaohms.Measuring voltage between any of those pins with the device powered on gives me millivolts at best, I suspect it's just noise. I've tried just putting LEDs in either polarity across all of the lines with no success.I suspected the output of this to be 2 optocouplers (the different voltage drop depending on polarity between pins 1-2 suggests it's a LED, and the 0.175V drop between pins 3-4 might be the phototransistor?), so I've tried making a circuit with putting one side of pins 1-2 (which I suspect is to be the LED, aka inbound channel) to 5V and the other to a USB-TTL serial converter's TX pin and a 220ohm resistor and sending data that way, and for pins 3-4 I connected one side to ground and one side to the RX pin of the serial converter through a 220ohm resistor. However the only thing I've managed to achieve is to get my own input echoed back to me, and I'm pretty sure that's due to my wiring rather than the device actually echoing anything.Questions:1) am I correct that my measurements likely suggest there's optocouplers connected directly to the port? That would also explain the lack of voltage on the port. The board has 8-pin chips marked 631-819 which might be HCPL-0631-like optocouplers?2) if so, is the setup of having optocouplers straight onto what seems like a fairly heavy-duty port common? Searching around for RS485 and optocouplers shows schematics where the optocouplers are used to isolate between the MCU and the RS485 driver (with that driver being on the "isolated" side), where as here the optocouplers would be *after* the RS485 driver?3) There is 1 RS485 driver per port, and my understanding is that it's only got A and B as outputs. How come there are 4 lines per port? Could it be RS-422 instead? The datasheet of the RS485 driver mentions RS422 as well but I'm frankly not sure how you'd go from the A and B pins of that chip to RX+/RX- & TX+/TX- of RS422.4) as a general rule, what's the common max current for an optocoupler LED to be sinking, and what's the max current for a phototransistor? I had ~20mA (at 5V) for the LED and ~2.3mA for the phototransistor, which seem like safe enough values for conventional LEDs but now that I think of it, I may have blown the optocouplers with my experimentation already? Also, is the phototransistor of an optocoupler vulnerable to reverse polarities (at the aforementioned 2.3mA current)? If so may have blown it already in this case and might need to do a repair.5) do the measurements described above sound familiar to anyone? The 120ohms between pin 3-4 and the 56k between pin 2 and 3&4 seem too "perfect" to be a random coincidence? Does this look like a common component or some standard port?6) finally, how do I interface with this? I've got Arduinos, ESP micros, RS485/422 to USB converter and basic electronic components such as resistors and diodes - can I make something with this to hopefully be able to talk to it and get its responses?Here are a couple photos of the board (I will get better ones next time I take this apart) - the 4 black components right below the RJ45 ports are marked ST485EB:https://ibb.co/ZMzjs97-https://ibb.co/K9WVwHL(note that I used an external image host that might be a bit dodgy, so adblocker recommended - unfortunately the forum itself wouldn't allow me to upload images that big and resizing would make component labels even less readable than they are now).Regards.

author: tooki
author_rank: Super Contributor
timestamp: March 22, 2023, 08:13:31 am
content: (I’m on my phone where editing bbcode is a PITA so I’ll just reply to numbers.)1. The optocouplers and RS485 transceivers have to get power from somewhere. In theory one of the pins of the RJ45 ports could be power (so you’d have A, B, GND, and power.) Or there might be an isolated DC-DC converter.2. You use optocouplers between the transceiver and the rest of the circuit, whatever it is.3. You could use this part for RS-422 or full-duplex RS-485 by using two of them. You’d configure one to always be an active transmitter and the other to always be an active receiver.4. It varies by model. I’d check the data sheet, since I think you have identified the optocoupler.5. 120 ohms sure sounds like an RS-485 terminator.6. If it’s using UART serial over the RS-485, then you should be able to cut up an old Ethernet patch cable to connect to it using your USB to RS-485 dongle. Then you just use a terminal program like CoolTerm to talk to it.But bear in mind that RS-485 is only the physical layer: it defines the fundamental electrical characteristics, but doesn’t say anything about the protocol you transmit over it. There are many, many systems that use RS-485 as the physical layer, like Modbus, DMX512, and many others. While it’s certainly super common to use it for UART serial, in theory it could be a completely proprietary binary format, or even just unencoded on/off signals.

author: Rjevski
author_rank: Unknown
timestamp: March 26, 2023, 03:21:00 am
content: Thanks for your reply.I took the device apart again and managed to reverse-engineer the board layout for the communication ports. I was incorrect in thinking that the optocouplers were *after* the RS485 transceivers - that's not the case, the optocouplers arebefore, and the design in the end turns out to be close to a typical opto-isolated RS485 interface.The pinout of the RJ45 ports is as follows, for anyone else stumbling upon this:Code:1 -> ground (local optoisolated ground for that port & its respective transceiver, separate from other ports or the main device ground)2 -> positive, tied to a 7805 regulator providing the isolated power rail for the transceiver & optoisolator3 -> RS485 line A, tied to pin A of the RS485 transceiver4 -> RS485 line BProviding power within the 7805 regulator's tolerance (I provided 10V) powers up the port, however still no unprompted output. In response to any traffic however the machine does output "0x00" bytes in response to anything transmitted (not sure if that's the behavior of the device or if my setup is wrong) so I will be doing more investigation on that, but marking this particular thread as solved.