I'm trying to establish communication between two boards, one of which has an RS232 output and the other with an I2C input. I've looked for adapters online and the only ones I've found seem to be RS232 to USB, which is not what I'm looking for. Is there a limitation in the technology that I've overlooked? What is the difficulty in converting RS232 to I2C?
closed as unclear what you're asking by brhans, Chris Stratton, TonyM, RoyC, Huisman Jul 22 at 21:56
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
I2C is half-duplex. RS-232 is full-duplex.
I2C has addresses, RS-232 does not.
I2C specifically writes/reads registers at the destination. RS-232 just send arbitrary bytes.
They are completely different protocols used for completely different things. There is no set relationship between the two and so there is no way to generic way convert between the two. Whatever device sits in between needs to know the context of the messages being sent and received since it must read and re-interpet the messages.
It's like asking why can't I find something that automatically converts books into movies? You just can't run it through a set process. You need someone who knows both books and movies to sit down, go through the book, re-interpret it coherently, then make the movie.
Or it's like trying to translate cultural references in media works. You can't just run them through a set algorithm. You need something in between that understands both languages (understands both protocols) and understands both cultures (knows the context) to do the translation. Hell, it's tough enough to translate cultural references even when you don't have to worry about the language.
RS-232 is a full-duplex streaming protocol with no special meaning of individual bytes. I2C is half-duplex, and bytes have meaning (address, subaddress, data). So to interface the two you need some protocol conversion.
There's two approaches you can consider: wrap I2C in serial, or serial in I2C.
As an example of wrapping I2C in serial, I faced this issue many years ago when I had to interface a SPARC host to a video acquisition board with I2C control. I used a microcontroller that connected via serial to the SPARC; the micro ran a small command interpreter that dealt with I2C primitives. The micro did the equivalent of Linux ‘i2c_set’ and ‘i2c_get’; it understood I2C addressing as well as single- and multiple-byte transactions.
If I faced this issue today, and it was a one-off, I’d use something like the Totalphase Aardvark which uses USB. It has an API that supports those primitives.
To wrap serial in I2C, realize that it's possible to model a bidirectional serial link using the I2C multi-master capability. This allows multiple devices to talk to each other in a basic network. To support this your I2C device needs to be able to support both master and slave, as would your serial-to-I2C bridge (likely a microcontroller in this case.) Further, as a master device your elements need to deal with I2C arbitration. Not a big deal, but check.
Each I2C slave would then map a register as an RxD serial queue. When a master wants to send data to a slave, it posts bytes to the slave's RxD port by expanding the serial byte or bytes to the I2C address/subaddress/data sequence. The slave would see the byte(s) being posted, pull them from the register, and post them to its serial queue, much like how it would deal a normal UART.
The I2C arbitration mechanism deals with any contention issues if two devices want to send data at the same time.
Ultimately, from an application point of view you'd have a full-duplex serial connection.
Bonus - a possible commercial solution that does this: https://ncd.io/serial-to-i2c-conversion/