Last Updated
    2 / 28 / 12
Original Site



    Path: BinaryBedlam > Krill Labs > procedures > How-To > Convert TTL to RS using MAX232    


     
   
Convert TTL to RS using MAX232
Developed:        
3/21/11


Status:
In Use


Summary:
Force an MCU to adhear to tighter RS-232 standards.
-OVERVIEW-




About:
      I ran into quite a number of issues when trying to use the Max232 chip. I found lots of articles online regarding how to wire the thing, but none cover any of the details on properly using it. It's a simple circuit to build and integrate, but there are a bunch of prerequisites to actually making it work. And if I didn't have an Oscilloscope, I probably would have never figured it out myself.






Establishing a Baseline:


      
      First off, here is what a waveform from a computer's serial port should look like. I am transmitting [space] & "." back to back. Note the amplitudes, 1 = -15v and 0 = 15v.






      
      Here is the same waveform as produced directly by my Pic Processor. The amplitudes are now 1 = 0v and 0 = 5v.






Notes So Far:
      RS-232: idles on logic 1, low = 1, transmits a logic 0 to signify a start, high = 0, and sends the LCB first.

      You DO NOT need the MAX232 chip to interface the processor directly to the computer's serial port. A PC's comm port is capable of translating the TTL levels with out any additional hardware. Just make sure the PIC is using non-inverted comms.

      Also, When building the MAX232 circuit, it is not necessary to use consistent capacitors. I didn't have any 1uF caps in my stock, so I had to go to Radio Shack. And even "The Shack" was on the short side, they only had 2 tantalum and 2 electrolytic caps at this value, and I needed 4, so I had to mix and match.







Hooking up the Converter:
      Now here is the waveform out of the MAX232 converter (as produced by the PIC). The amplitudes are now 1 = -10v and 0 = 10v. But look closer at the waveform, it's upside down! This chip inverts the signal. No one ever mentioned that!

      To correct for that, you have to invert the comms at the PIC to compensate. Two inverts make a right. This is usually simply done when defining your system type, i.e. instead of using N9600, try T9600 (T=true, N=non-inverted).

      Also note that the waveform idles low prior to the sequence, but idles high after the sequence. This is also a problem. This was caused by another section of my program blindly setting all of PortC to 0. Keep in mind, the Rx and Tx pins are also on PortC. To account for this, make sure the Transmit pin is initialized high then never reference it again in your program. Now that we are using inverted comms, the PIC's Receive pin has to be high for steady state (not receiving anything), and it's transmit pin also needs to remain high, so don't accidently toggle it to 0 in your code like I did, because if you do, the receiving end wont be able to tell where the sequence actually starts.



After the Adjustments:


      
      Here is the waveform of the converter after initializing the Tx pin high and inverting all the comms. Much Nicer!






      



      Here is an explanation of the waveform.






More Notes:
      Another thing to watch out for, If your program is supposed to simply echo back the bytes it receives from say hyper terminal, but it seems to come back garbled, yet bytes transmitted on the PIC's own accord, like a boot up sequence seem to come back ok, it is more than likely because you are attempting to transmit too close to a receive. Try placing a 500us pause between the part of your code that receives the string and the part that echoes it back out.









Viewer Comments

Name: Scott
Time: 10:28 PM
Date: March 22, 2011
Comment:     Too Cool! I`ll bet the guys in the lab, at least the Chinese guy, would be fascinated. Those are handy people to know.


Name: Kev
Time: 04:42 PM
Date: March 23, 2011
Comment:     you have your own o-scope?! :o!!


Name: dankrill
Time: 05:37 PM
Date: March 23, 2011
Comment:     I wish, actually I borrowed this from one of the labs at work.


Name: Andre,
Time: 06:47 AM
Date: March 25, 2011
Comment:     One day Daniel will show me how to use the o-scope. I don`t remember how to use it.


Name: Waalkes
Time: 06:46 PM
Date: March 25, 2011
Comment:     Great posting Dan!, but I would add that the serial port on your PIC sends the byte out with the least significant nibble first, then the most significant nibble (little endian), and with the bit ordering reversed. Depending on what you are connecting to this could end up being an issue.





Leave A Comment


NAME: REMARK:









BinaryBedlam's Basic Web Development 2010© .
Created by Dan Krill of BinaryBedlam ; Krill Labs and any of its subsidiary components, which include but are not limited to: Graphical Design and Layout, Images, and Decals;
are the property of the owner and should not be used with out expressed written consent from the web administrator .