To MAX232 or not to MAX232

Discussion in 'Embedded Systems and Microcontrollers' started by sandraos, Jun 22, 2009.

  1. sandraos

    Thread Starter Member

    Jun 8, 2009
    12
    0
    -- New to electronics and microcontrollers --

    I have seen a lot of schematics on how to interface the 8051 with a serial port. They all include the Max232 converter. Then I came across Wichit Sirichote's page and I found this: http://www.kmitl.ac.th/~kswichit/ap275/ap275.htm

    I hooked it up as can be seen in the attached schematic.
    It works wonderfully (through Hyperterminal). The program is at the bottom of this message.

    Here are my questions:
    - Why is it bad to hook it up like that?
    - Will it damage the microcontroller if hooked up like that?
    - What is the purpose of the Resistor-Capacitor combination on the RST pin (pin 9)?
    - Any other comments on the other resistors (still don't understand pull-up and pull-down's purpose), the diode, and the transistors are welcomed and appreciated.
    - Also any comments on the program and schematic are also welcomed and appreciated as well.

    Thank you in advance for all your help and comments,
    Salim

    //------------------------------------------------------
    sfr at 0x87 PCON;
    sfr at 0x89 TMOD;
    sfr at 0x8D TH1;
    sfr at 0x98 SCON0;
    sfr at 0x99 SBUF0;

    sbit at 0x8E TR1;
    sbit at 0x98 RI_0;
    sbit at 0x99 TI_0;

    void SerialLoop(void);

    void main(void)
    {
    SCON0 = 0x50; // 01010000 bin. 8-bit UART; timer baud rate
    TMOD = 0x20; // 00100000 bin. 8-bit auto reload timer
    PCON = 0x80; // 10000000 bin. SMOD_0 on. Double the baud rate
    TH1 = 253; // baud rate of 19200 with SMOD_0 and 11.0592 MHz
    TR1 = 1; // turn on timer

    while (1)
    SerialLoop();
    }

    void SerialLoop(void)
    {
    unsigned char Acc;

    while (!RI_0){} // wait for RI_0 = 1

    Acc = SBUF0; // move buffer to accumulator
    RI_0 = 0;
    TI_0 = 0;
    SBUF0 = Acc; // move accumulator to buffer

    while (!TI_0){} // wait for TI_0 = 1
    }
     
  2. russ_hensel

    Well-Known Member

    Jan 11, 2009
    818
    47
  3. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    You don't need a MAX232 unless it's for a commercial product that MUST have proper RS232 compliance. Even then, almost every old PC mouse you could buy (remember the old mouse with a ball) used this single transistor system to generate the serial to the PC, and the UARTS in the PC for the serial mouse are the same as the one on the PC serial port. I've never met a UART that actually wouldn't work with 0v-5v logic levels.

    I think it's like a conspiracy by Maxim to convince everyone they need a MAX232, seems that everyone believes it anyway it's been a very successful conspiracy. ;)
     
  4. sandraos

    Thread Starter Member

    Jun 8, 2009
    12
    0
    Thanks for the replies guys. Although I was hoping for something more concrete on "why" it works as well :)
     
  5. StayatHomeElectronics

    Well-Known Member

    Sep 25, 2008
    864
    40
    The circuit that you show converts the voltages from 12V RS232 standard to 5V that can be safely read by the uController, that is the receive side. The transmit side works because RS232 transeivers are probably defined over a range of voltages to compensate for the distances between the two communicating devices. (Read up on Bipolar Junction Transistors if you need more detail on the actual operation of the transistor circuit. This is a very basic circuit.)

    Your circuit probably doesn't have the range to match the standard but for close distances it will probably work fine. The MAX232 probably also has ESD protection which could affect your circuit since connections are being made right at the transistor.

    The resistor/capacitor combination on the RST pin guarantees the device gets properly reset on powerup. On powerup, the capacitor has zero volts across it and therefore pulls the RST pin HIGH, causing a reset. The capacitor charges at a rate controlled by the resistor to gradually pull the RST pin low and out of reset.

    Pullup and pulldown resistors are used to put an input pin in a known state either on powerup or in the absence of a external driving circuit.

    In your circuit, the transistors act like switches controlled by the base current. They allow for a digital signal.

    The diode limits the voltage at the base of the transistor to -0.7V. It does not affect the positive side if selected correctly. This is so the transistor does not get damaged by overdriving it in the wrong direction
     
  6. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    And both the RS232 TX and RX need to be inverted, which is accomplished by the same 2 transistors.
     
  7. Vaughanabe13

    Active Member

    May 4, 2009
    102
    5
    Exactly right. You don't need the full 12V level for a computer terminal to read the signal correctly. Windows does a pretty good job of recognizing the communication at imperfect voltage levels. That being said, a MAX232 or equivalent chip will do it *better* but it isn't the only way to do it. That transistor setup looks fine.
     
  8. sandraos

    Thread Starter Member

    Jun 8, 2009
    12
    0
    Thanks again... I ve been using it like that for a few days now and it works better than through the Dallas Semi development board (some of the shift-key chars come out weird).
     
  9. embedded678

    New Member

    Nov 27, 2012
    1
    0
  10. MrChips

    Moderator

    Oct 2, 2009
    12,421
    3,356
    Don't be fooled. RS-232 was invented with specific characteristics to serve a specific purpose. Omit a proper RS-232 receiver/driver at your own peril.
     
    ErnieM likes this.
  11. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    Looks like a pretty blatant thread hijack to me.

    But to participate in the crime: however we interface with RS-232, it's less and less useful, because there just aren't many ports of that type around any more. USB is what we have to do, and it's much less controllable by hobbyists. But on the other hand, if you don't need much power, the computer will supply +5V over the cable, and that's useful.
     
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    QFT. Agreed.

    However, RS-232 was developed for long haul transmission, so if you are just going 3 feet or so to your PC for a breadboard you would probably get away with a cheapie interface such as these.

    Sparkfun sells something similar. I almost ordered one until I checked the schematic. Not for me.
     
  13. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    The chips have been designed for instance to survive transients in professional environments.

    There is nothing wrong as such with using transistors. If you also need the control lines, you end up with quite a few components.

    The MAX chip contains some 1400 transistors, they must be good for something.

    Normally you'd rather use an IC than 10 individual components.

    RS232 was designed in the 1970s! It is not so bad but has limits. For instance transfer rate.

    If you ever used high speed SPI then you will know about the transfer limits, and required compensation.

    The cables are also more bulky and more expensive than USB.

    If your stuff works then fine- but think it may not work in some professional environment. Or rather say, it will fail/cause problems at some point of time.
     
  14. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    RS-232 was first introduced in 1962 by the Radio Sector of the EIA.
     
  15. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    I've noticed lately that many USB-RS232 converter cables have trouble with TTL level i.e. non-MAX232 lines (which I too have used many times for simple / cheap debug interfaces). If you just need it for setup, test etc. and cost is an object, you can pin +5 out with the raw serial and use that to power a MAX232 in a cable/dongle.
     
  16. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    Not so many people had access to computers. There have been some in the late 1970s, but the so-called "home computers" mainly evolved in the 1980s. Many of these had serial ports, including RS232. The IBM PC was introduced 1981. It was one of the first mass produced computers, which was available for personal usage on the regular market.
     
  17. MustardMan

    New Member

    Dec 11, 2014
    1
    0
    What! Windoze has absolutely nothing to do with doing a pretty good job. It is the hardware, and solely the hardware!

    As pointed out elsewhere, RS232 is specified to several hundred 'feet' (meters was a strange unit back in the 60's & 70's), but well over 50 meters anyway. Try getting USB to go that far without special gear (the specification tops out at about 3 meters AFAIK).
     
  18. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Hi MustardMan, welcome to the forums.

    Please try to refrain from resurrecting posts from ages ago. While what you say is correct there is no need to add anything to such an ancient thread where the thread starter has long since left.
     
Loading...