5
\$\begingroup\$

I have a Microchip PIC with UART support. If i understand correctly, the UART is able to natively handle the TTL serial signal.

I'm expecting input signal that should be TTL (0/5V), but it could be RS232 (+/-13V).

  1. What would be the best way to handle both different signals. Anyway to auto detect the (incoming) signal?
  2. Or should i have a manual switch that allows for signal selection?

I was thinking of using a something like a MAX3232, but i'm not sure what would happen if that IC gets a TTL signal.

Thanks!

\$\endgroup\$
  • \$\begingroup\$ Why could the signal be either TTL or RS232? It seems like this should be set in stone. If you interface an RS232 level signal directly to a PIC, the IC could be destroyed by the high voltage. \$\endgroup\$ – Nate Aug 16 '13 at 21:58
  • \$\begingroup\$ My hardware interfaces with as industrial scanner. Reading the manual, it says that the scanner can be set in either mode. By just scanning a barcode you can change this mode. And i would like to make sure my PIC doesn't burn when that happens. Maybe just input protection? \$\endgroup\$ – Roger Aug 16 '13 at 22:00
  • \$\begingroup\$ Do you want to detect the type of serial in your circuit automatically? \$\endgroup\$ – Chris Laplante Aug 16 '13 at 22:06
  • \$\begingroup\$ @SimpleCoder, it depends at what cost. But if it could be done relatively easy yes. Otherwise, maybe input protection would be easier? \$\endgroup\$ – Roger Aug 16 '13 at 22:07
  • \$\begingroup\$ The easiest way to do it non-automatically would probably be an oscilloscope. As far as automatic, I'm not sure - maybe you could use some kind of circuit to detect the peak voltages (RS232's swing is much wider than TTL). \$\endgroup\$ – Chris Laplante Aug 16 '13 at 22:09
1
\$\begingroup\$

Simple steps as follows...

The first step is to disable the driver attached to the PIC (No point damaging the equipment with excessive voltage)

Then monitor the in coming signal from the device and detect if they are Negative Wiki RS232 Voltage wave form

Then decide which mode the PIC should use. TTL is only positive. RS232 has a good -V and +V swing around 0V. It may be a good idea to detect more than -1V just in case of noise etc.

\$\endgroup\$
0
\$\begingroup\$

Expanding on test engineer's answer:

First, a couple facts about the levels: The idle (mark) state of the line should be less than -3V (and not less than -15) when an RS232-compliant device is connected. Conversely, the idle state of a TTL-serial device should be between 0 and 0.8 V.

So, I think the easiest way to detect which type of device is connected is something like the following:

schematic

simulate this circuit – Schematic created using CircuitLab

For TTL-level signals, the device will pull up Rx pin on the board to 5V, and so the microcontroller sense pin will see a logic high. When an RS232-compliant device is attached, the idle state of the line will be between -3V and -15V. The two resistors form a divider, so the sense pin will see less than 0.8V (when the input is -3V). D1 prevents the sense pin from going more than a few hundred millivolts below ground for stronger signals, and the D2 zener protects against positive inputs greater than +5V (the RS232 space state).

Depending on the baud rate your scanner uses, the above circuit may even be sufficient to condition the input (ie, you might be able to connect both the micro-controller's RX pin and sense pin to the line labeled "To uController sense pin." The one difficulty with this is that RS232 uses negative voltages to represent 1's and positive voltages to represent 0's, which the opposite of what is used in TTL-land. To fix this, you'll want to add an XOR gate, like so:

schematic

simulate this circuit

Now, the "from uC invert" line is connected to an output on your micro. When it's high, it inverts the received signal, and when low passes it normally.

\$\endgroup\$

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.