PDA

View Full Version : Direct PIC to PC without MAX232



acjacques
- 4th October 2006, 22:07
A good idea in order to have a direct PIC and a PC bilateral communication using the PIC's UART and HSERIN and HSEROUT without an external inverter like MAX232 is choose a PIC with Comparator Module like the 16F877A or 16F88 or 16F628.

You just need configure the comparator module as "Two Common Reference Comparators with Outputs" where the output of comparators are redirected to pins. Then the TX pin used to HSEROUT is hardwired to the input of comparator 1 . The inverted output (true) is now outputed in the C1.

To receive from PC serial is directed to input of C2 and output is hardwired to RX pin used by HSERIN.

Both comparators may use the internal reference (Comparator Voltage Refrence Module enabled and routed to C1, C2 ) or use an external.

I already have tested this trick with 16F88 with good results.

Of course this is not the true level converter like the MAX232 but works fine in my PC.

I hope this be useful for some users.

ACJacques

dhouston
- 14th October 2006, 14:41
Neat idea.

I was hoping to use it with a 16F688 but C2OUT and TX share RC4.

swr999
- 22nd September 2014, 06:11
Thank you for this idea!!

Also, would the following work:

HSEROUT - First invert all bits in the data byte, then send with HSEROUT.
HSERIN - Read the data as usual, the invert the data byte prior to using.

Thanks!

Charlie
- 22nd September 2014, 14:31
Thank you for this idea!!

Also, would the following work:

HSEROUT - First invert all bits in the data byte, then send with HSEROUT.
HSERIN - Read the data as usual, the invert the data byte prior to using.

Thanks!
Sorry, won't work. You need to invert everything, including the idle state, start and stop bits, etc.

Demon
- 22nd September 2014, 15:20
No risk of overvoltage on PIC?

Robert

tumbleweed
- 22nd September 2014, 19:33
No risk of overvoltage on PIC?
Yes, this exceeds the max voltage spec on the pins. Bad idea, esp the negative voltage.

RS232 levels could be as much as +/-25V, although you normally won't see them anywhere near this high out of your typical PC.

If you're interested, read TB3013 (http://ww1.microchip.com/downloads/en/AppNotes/93013a.pdf). Then see if you still want to recommend doing this.

Charlie
- 23rd September 2014, 14:29
It's simple enough to protect the device with a series resistor and clamp diodes to limit the excursion to the rails give or take a diode drop. You only need to protect the receive, of course.
I'm not sure I'd recommend this for a commercial application, but for a hobby build it would be fine. Of course, many of the devices offer the ability invert everything, set up by the UART configuration bits. But if you have a device without that capability, this is a "quick and dirty" way to get communications going.

tumbleweed
- 23rd September 2014, 14:44
It's simple enough to protect the device with a series resistor and clamp diodes to limit the excursion to the rails give or take a diode drop
Right, but that's not what the OP suggested. FWIW, Fig 3 in the PDF suggests some simple ways of protecting the input pin, including your method.

swr999
- 23rd September 2014, 18:59
Sorry, won't work. You need to invert everything, including the idle state, start and stop bits, etc.

Of course you're right! Why didn't I think of that? ;-\
I'm just using a 3-wire connection, so I suppose, aside from a dedicated RS232 translator chip (MAX232 etc), I could use any scheme to hardware-invert the Rx and Tx lines?
Thanks for the helpful responses!

Charlie
- 24th September 2014, 14:19
Of course you're right! Why didn't I think of that? ;-\
I'm just using a 3-wire connection, so I suppose, aside from a dedicated RS232 translator chip (MAX232 etc), I could use any scheme to hardware-invert the Rx and Tx lines?
Thanks for the helpful responses!
You can use any scheme to invert the signals and it will work, bearing in mind that you might encounter an interface that it won't work with because it doesn't strictly meet the spec. You'll have more success with a 5V PIC, and you should protect any input from overvoltage on whatever device you use. I do this all the time for one way communication out of the PIC for dumping status logs or other information that doesn't require a response from the computer. Typically, I use an N-channel FET to do the inversion, but a spare comparator or op-amp will do too.

Demon
- 24th September 2014, 18:12
..., I use an N-channel FET to do the inversion...

Not P-channel?

Robert

Charlie
- 25th September 2014, 15:57
P-Channel devices are usually more expensive and have other design considerations, so I design 99% of the time with N-channel and have several devices rolling around my parts bin when I need one. It's 6 of one, a half dozen of the other. You might be able to save a little power by using one or the other, since a comms channel is usually idle a lot - I have not had a design where I needed to care about power and also needed a cheap comms interface, so I really have not thought it through.

acjacques
- 26th September 2014, 02:09
About the protection of PIC input pin lets go remember that generally input pins already have positive and negative clamp diodes built in the chip. I have tested even without a series resistor but 470R will do the job. The great majority of legacy RS232 ports already are 0- 5v compatible for input and are current limited for output.

tumbleweed
- 26th September 2014, 10:53
Here's a good example of the strange things that can happen when you get creative and choose not to pay attention to the specs...

PIC16F1847 HFINTOSC Slow and Unstable (http://www.microchip.com/forums/m822902.aspx)

Note that this guy WAS limiting the current with a series resistor.

swr999
- 23rd October 2014, 22:32
Back to my original question:
Turns out that the 12F1xxx family (and likely others) have an option to invert data from the TX/CK pin. The control is the SCKP bit (bit 4) in the BAUDCON register, described on page 279 of the 12F1822 data sheet.