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?

  • \$\begingroup\$ Well, start with the fact that I2C is a one-to-many or even many-to-many protocol, while RS232 is point-to-point... \$\endgroup\$ – Eugene Sh. Jul 12 '19 at 17:44
  • \$\begingroup\$ There's also a voltage level problem. I2C is typically at TTL, but RS232 typically isn't. Have you tried searching for 'UART to I2C' instead? \$\endgroup\$ – Chris Fernandez Jul 12 '19 at 17:48
  • \$\begingroup\$ RS232 is a per character high voltage (+/-4v min) protocol while I2C is a multibyte low voltage (3-5V) serial protocol. You need an MCU in between to do protocol conversion. Even if both were 3-5V level (TTL serial levels) you still cannot connect the two. \$\endgroup\$ – Jack Creasey Jul 12 '19 at 17:50
  • 2
    \$\begingroup\$ The task is ill-defined enough that you typically need to either build a custom translator as an MCU firmware, or else have one of your existing ends be willing to talk the foreign protocol as encapsulated by an intermediary translator, which can at times be extremely awkward, especially if latency vs stall limits means you end up having to proactively cache responses to likely I2C read requests over serial. \$\endgroup\$ – Chris Stratton Jul 12 '19 at 18:35
  • \$\begingroup\$ As others have said, they don't share a common protocol so there's no straight conversion. RS232C is a byte transport protocol. I2C is a multi-byte message protocol that carries at least two bytes to be useful (address/dir and data). You'll have to think deeper about what you're actually trying to achieve. \$\endgroup\$ – TonyM Jul 12 '19 at 19:08

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.

  • 1
    \$\begingroup\$ This analogy misses some possibilities, because while the I2C<>Asynchronous Serial task is ill-defined, it does often have possibilities of literal encapsulation which pushes the "work" of dealing with the foreign protocol off to the end user. That would be the equivalent of publishing a movie screenplay in a book form (vs a novelization), or making a movie of someone reading the book out loud. \$\endgroup\$ – Chris Stratton Jul 12 '19 at 18:35
  • \$\begingroup\$ I'm open to better analogies. I just couldn't think of anything better. \$\endgroup\$ – DKNguyen Jul 12 '19 at 18:38
  • \$\begingroup\$ In a way it does work, if you allow for the "cheap" solution of the screenplay or the "cheat" of having a narrator read the book. Computers don't get bored, so it's more practical than it feels - though they can be swamped with work. \$\endgroup\$ – Chris Stratton Jul 12 '19 at 18:40
  • \$\begingroup\$ Perhaps a more accurate analogy is translating cultural references between languages in media. You can't just mechanically convert word-for-word. You need someone who understands both languages (knows the communication protocols) and both cultures (i.e. knows the context) to reinterpret things. \$\endgroup\$ – DKNguyen Jul 12 '19 at 18:42
  • 1
    \$\begingroup\$ Well, again, you can also literally translate the words and make the reader sort out the meaning. In fact the practical knowledge of more than one construct in a language I was learning has been reinforced by hearing its speakers' mistakenly try to use it with English words. You can study a culture or even its grammar without learning any of the original vocabulary. \$\endgroup\$ – Chris Stratton Jul 12 '19 at 18:52

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/


Not the answer you're looking for? Browse other questions tagged or ask your own question.