6
\$\begingroup\$

I am trying to interface my ATmega chips to the computer using a serial interface. I have read that this can be done directly by connecting the appropriate pin between the chips and the serial pin. But it is advised that I use a MAX232 chip. What is the purpose of this chip and do I really need to use it?

I ask this because in a project I am making, there is a big size constraint and the chip might take up valuable space.

\$\endgroup\$
12
\$\begingroup\$

If you need to connect the AVR to the computer using the serial port and a "standard" DB9-DB9 serial cable, yes, you need to use an RS232 transceiver in circuit. The AVR's UART outputs 0-5V signaling. The RS232 spec is +/-15V signaling, and I believe it's also "inverted" with compared to UART signaling. You don't have to use specifically the MAX232, but you do have to use a RS232 transceiver. These chips (plus some external capacitors) handle the voltage level conversions (via charge pumping) in either direction as well as the signal inversion, and act as "line drivers" driving longer lengths of wire allowed by the RS232 standard.

Alternatively, you can use a cable that includes such a transceiver circuit embedded in the DB9 shell if you are space constrained on your board. Yet another alternative involving a cable is to use a cable that includes an FTDI FT232 chip in it, which has the advantage of making it look like a COM port over USB to the computer, but you're looking at upwards of $15 for that cable.

\$\endgroup\$
  • \$\begingroup\$ Hey, if I connected the MAX232 chip, it would still be a COM port but over serial right? I was thinking of using an FTDI but where I live it isn't available easily. \$\endgroup\$ – Rick_2047 Feb 18 '11 at 5:30
  • \$\begingroup\$ @Rick, yes it would still be a COM port, very likely COM1 or COM2 \$\endgroup\$ – vicatcu Feb 19 '11 at 5:07
  • 2
    \$\begingroup\$ @Rick also a word of caution - beware of getting pins 2+3 (rx+tx) backwards :) \$\endgroup\$ – vicatcu Feb 19 '11 at 5:10
  • \$\begingroup\$ So does the MAX232 simply provide what RS232 over serial needs whereas an FTDI chip provides USB/UART capabilities? I guess I am confused on what FTDI brings to the table..er...cable. lol \$\endgroup\$ – cbmeeks Feb 4 '15 at 21:22
  • \$\begingroup\$ @cbmeeks FTDI converts/transcodes a USB CDC device to a UART interface. MAX232 is (more or less) as straight electrical interface translation, which is to say RS232 and UART are quite similar protocol-wise. That is not so for USB CDC and UART. USB and RS232 have little to do with one another. \$\endgroup\$ – vicatcu Feb 6 '15 at 16:04
5
\$\begingroup\$

The RS232 specification requires a signal voltage of between -3 and -30V for a logical '1', and a signal voltage of between +3V and +30V for a logical 0, input impedance is around 3k and output impedance should be around 300 ohms.

If you're going to implement a fully complient interface then yes, you will need something like the MAX232 - or an alternative, like the MAX3221 which does come in a quite small TSSOP package.

Alternatively you could utilise one of the handshaking lines from the DTE (PC or similar) to supply the negative voltage and use a simple transistor level changer to handle the signal inversion (from the MCU) and level shifting. This does however require that the DTE is configured such that it's handshaking lines are in a suitable state.

Another option is to take advantage of the fact that most equipment these days implements RS232 using something like a MAX232 device. While these are fully complient with the specification they also extend things so that the input levels are basically +2.8 to +30 for a logical '0', +1.4 to -30V for a logical zero (from memory) - in other words the receivers actually include TTL signal levels. So you can just invert the signal on the UART pins and pass it out directly to the DTE device. This technique is used on quite a few devices including many handheld GPSes. I'm not saying you be 100% compatible but you'll find this works more often than not.

You still need to invert the UART signals (unless you're bit-banging the pins yourself), two inverters should be smaller than the MAX232 plus associated circuitry, but probably not by much.

\$\endgroup\$
  • \$\begingroup\$ I don't know about ATmega, but many PIC UARTs can invert the output. Read the datasheet. \$\endgroup\$ – markrages Feb 18 '11 at 15:36
  • \$\begingroup\$ It's actually +25V maximum, with +15V being a typical limit. \$\endgroup\$ – Thomas O Mar 6 '11 at 21:31
0
\$\begingroup\$

I am no AVR expert, but i believe there is a usb 'bitbanging' library to use it as an usb device. You might be able to use that to emulate a serial port.

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

As vicatcu said, you do need something to translate the signal levels from the mcu to something the PC's serial port expects. You don't have to use a MAX232 or similar -- Sparkfun has something that would work.

\$\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.