3
\$\begingroup\$

I'm talking to a sensor using RS232 and the UART of an mbed. However I've noticed that the bits sent to and from the sensor are the exact complement of what they should be. What my mbed sees as a 1, the sensor sees as a 0, and vice versa. I cannot change the sensor, nor to I want to change any of the hardware. How can I invert the input and output of the mbed's UART? The mbed uses a Cortex M3 processor.

EDIT: sorry for any confusion. The whole line is inverted. That means that the start and stop bits are inverted as well. The first bit in the message is luckily a 0 (read as a 1), and the processor interprets that as my start bit. This causes everything to be frame shifted by one bit. Luckily the processor is ignoring framing errors.

\$\endgroup\$
10
  • 2
    \$\begingroup\$ In code? Invert your ouputs before you send them, invert anything you receive before using it? \$\endgroup\$
    – Kortuk
    Oct 26 '11 at 22:59
  • 1
    \$\begingroup\$ What is the part number for the sensor? \$\endgroup\$
    – Oli Glaser
    Oct 26 '11 at 23:37
  • 1
    \$\begingroup\$ @Kortuk - That would be okay it it's only the data bits that are reversed, but if the line polarity expected is completely reversed (needs confirming) then the start/stop polarity will be wrong too so the data received will be garbage. \$\endgroup\$
    – Oli Glaser
    Oct 26 '11 at 23:47
  • 1
    \$\begingroup\$ Maybe you have an RS232 driver only on one side of the serial link, as the drivers invert voltage levels? \$\endgroup\$
    – starblue
    Oct 27 '11 at 7:31
  • 2
    \$\begingroup\$ Can you please post the type of sensor that you are using? An RS232 driver implies -12V/+12V signaling, I'd like to know if that's what you're getting in this case. \$\endgroup\$
    – Jon L
    Oct 27 '11 at 17:49
2
\$\begingroup\$

There is an RS232 driver chip on the board, this will be inverting the voltage levels.

Typically, a microcontroller UART will expect active high TTL level signals. A 0 is encoded as 0v, a 1 as VCC (usually 3.3v and/or 5v).

The RS232 PHY is intended for signalling over lengthy cables. It is active low and encodes 1 as -3v to -25v and 0 as +3v to +25v.

If the microcontroller is tolerant of these voltages on input pins and your UART is implemented in software then you can flip every incoming/outgoing bit (including start and stop bits). But, hardware support for this is rare.

If your microcontroller is not tolerant (and the mbed is not) then it could do harm to connect it.

The best solution is to intercept the active high TTL levels signals on the board and feed them direct to your microcontroller, avoiding the RS232 driver chip entirely.

Find the RS232 driver chip and identify its TX and RX lines. If you know the part number, find the datasheet then find the pins on the chip. If you don't know the part number, use an oscilloscope (or a continuity checker, or LED or buzzer) to identify the pins (send data from each end and look for the corresponding data line).

Once you've identified the pins, solder wires direct to your mbed, avoiding the RS232 driver chip, these should now appear at TTL levels, active high.

\$\endgroup\$
2
  • \$\begingroup\$ That would do it. I've found the data sheet for the driver, and it accords to the traces on the PCB, but I don't know if I can solder it. The driver is surface mounted to the PCB, and the pins are only 0.3mm apart. Is the best thing to do then get a driver for the mbed side? \$\endgroup\$
    – Hannesh
    Oct 27 '11 at 17:22
  • 1
    \$\begingroup\$ Soldering small pitch parts at home isn't as hard as you might think. Use a fine tipped soldering iron and some thin mod wire. Tin the wire with a little solder, touch it to the IC leg with a soldering iron. Fix the wire in place with a little glue to keep it secure. If you go wrong, apply a little solder flux to help any stray solder flow back. electronics.stackexchange.com/questions/4678/… \$\endgroup\$ Oct 27 '11 at 21:58

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.