I'm working on a flight control system that uses SBUS (a serial protocol), and the slave transmits inverted, so I had to invert it with a hardware inverter.

This isn't that big of a deal, but I'm curious as to why it can't just be done in software? This seems to be the case a lot of the time, that serial lines need to be inverted. Can't the receiving end just logical not every bit?

  • \$\begingroup\$ Fault cases? Boot up state? \$\endgroup\$ – winny Apr 20 '18 at 14:58
  • \$\begingroup\$ OSI has 7 layers and software that configurable only runs on the top a few. \$\endgroup\$ – user3528438 Apr 20 '18 at 14:58
  • 1
    \$\begingroup\$ Perhaps a better question would be why people design UARTs without configurable polarity on each I/O pin. \$\endgroup\$ – supercat Apr 20 '18 at 15:03

There are a few factors here.

  1. Single stage circuits are nearly always inverting. This comes from the fundamental behaviour of the transistors.
  2. The polarity of the input doesn't just affect the interpretation of data bits, it also affects the interpretation of start and stop conditions.
  3. Serial receivers are generally implemented in hardware.

Point 1 explains why we end up with inversion in the first place. An inverting line driver or line receiver is simpler than a non-inverting one.

Points 2 and 3 explain why if inversion is needed it must be implemented in hardware. On more modern hardware where logic is cheap and Pins are expensive there may be a programmable inverter inside the chip but not everyone seems to have realised this is a good idea yet, so there are many products out there with fixed polarity.

  • \$\begingroup\$ Invertors (and inverting gates) are both buffers / gates AND invertors. So they do 2 jobs for you. There are multiple in a package, so you can combine them. You can only combine AND gates to make more AND gates, or OR gates to get more OR gates. You can combine NAND gates to do most anything. The result of this is that people just habitually use inverting gate everywhere. \$\endgroup\$ – Henry Crun Apr 20 '18 at 21:35

The UART peripherals in smaller MCUs most often don't have any ability to invert the output bits.

You cannot just take the byte data returned by the peripheral and invert it in software because the asynchronous protocol requires a start bit edge of specific polarity.

Read the peripheral description of the relevant micro and compare with the typical serial protocol and you will understand.

enter image description here

In the above diagram, the timing is all from the falling edge of the input. In the case of RS-232, the idle state is called mark and is -5 to -15V and the start bit is called space and is +5 to +15V. The diagram above shows the typical output of an MCU, which is typically fed to an inverting driver to get appropriate RS-232 levels. If both ends of the interface use TTL inverted levels, then there is no need for an inverter (but of course you lose the advantages of robust RS-232 drivers which are supposed to be able to withstand shorts and connection to relatively high positive or negative voltages)

Since this is and transistors are virtually free, some micros allow the output polarity to be inverted with built-in hardware and a configuration bit, as supercat suggests, but it is far from ubiquitous.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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