3

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.

Hannesh
  • 257
  • 1
  • 3
  • 9
  • 2
    In code? Invert your ouputs before you send them, invert anything you receive before using it? – Kortuk Oct 26 '11 at 22:59
  • 1
    What is the part number for the sensor? – Oli Glaser Oct 26 '11 at 23:37
  • 1
    @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. – Oli Glaser Oct 26 '11 at 23:47
  • @OliGlaser, Ha, clearly I was tired to not think of start and stop bits. – Kortuk Oct 27 '11 at 04:55
  • 1
    Maybe you have an RS232 driver only on one side of the serial link, as the drivers invert voltage levels? – starblue Oct 27 '11 at 07:31
  • Yes, the whole line polarity is inverted. Luckily, framing errors are being ignored by the mbed. – Hannesh Oct 27 '11 at 15:48
  • @starblue, yes there is a RS232 driver on the sensor board! I didn't know they invert the voltage levels, can I get around this? – Hannesh Oct 27 '11 at 15:52
  • 2
    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. – Jon L Oct 27 '11 at 17:49
  • The sensor is not a publicly available part. It is a PCB with multiple chips on it. However, I can see that the RS232 driver on the sensor PCB is an ICL3232, and the microcontroller on the chip is an ATMEGA168. – Hannesh Oct 27 '11 at 18:06
  • Thanks for the reply. Joby Taffey's suggestion would work well then. – Jon L Oct 27 '11 at 18:17

1 Answers1

2

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.

Toby Jaffey
  • 28,796
  • 19
  • 96
  • 150
  • 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? – Hannesh Oct 27 '11 at 17:22
  • 1
    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. http://electronics.stackexchange.com/questions/4678/what-tools-equipment-and-techniques-do-you-use-to-solder-fine-pitch-smt-parts – Toby Jaffey Oct 27 '11 at 21:58