Programmers

All on one SLOW page
Serial Port
Parallel Port
Smart Programmers
Serial Loaders

Projects

ATmega8 Serial LCD
ATtiny2313 Serial LCD
ATtiny4313 Serial LCD
ATmega328 SIRC
ATtiny2313 SIRC
40-pin Dev Board
28-pin Dev Board
AVR PS/2 Keyboard
AVR MAX232 RTS/CTS
AVR Dual RS232 Ports

Minimal Circuits

ATmega16
ATmega32
ATmega644
ATmega1284
ATmega8515
ATmega8535
ATmega8
ATmega48
ATmega88
ATmega168
ATmega328
ATmega162
ATmega128
ATtiny13
ATtiny2313
ATtiny4313
ATtiny24
ATtiny84
ATtiny25
ATtiny45
ATtiny85

Other Stuff

ATtiny13 vs ATtiny85
ATmega8 vs ATmega88
ATmega16 vs ATmega164
ISP and SPI
MAX232 Arduino
A small FAQ
Hardware Info

RS232 using an AVR ATtiny4313 and MAX232

Introduction

The purpose of this project is to demonstrate the use of a MAX232 with an AVR, specifically an ATtiny4313, but the concept applies to all AVR's that have UARTS or USARTS. The MAX232 provides two RS232 transmitters and two RS232 receivers.

This circuit is in response to a specific question about AVR devices implementing RTS/CTS handshake. This is the hardware - I'll leave it to the reader to decide what to do with the software. It would be hard to provide code, since the implementation is fairly specific to the task at hand. This answer is specifically about RTS/CTS protocol, which governs master to slave communication. It does not have anything to do with slave to master communications, which is not really addressed properly, since at the time RS232 was being defined, the master was a mainframe, and the slave was a seriously dumb terminal or some other 75 Baud peripheral. A friend of mine has a Univac RS-232 port. It is the size of a two drawer file cabinet and takes two people to tip over.

Information

RS232 defines logic states, just like anyone else in the digital world, except for the fact that all signals in RS232 land are inverted, and are +/- 3 to 30 VDC. A logic "0" from the AVR point of view is 0 VDC, where the RS232 signal would be inverted and would be (typically) +12 VDC. When the AVR outputs a logic "1", it is at Vcc, which may be around +5 VDC. The RS232 driver will output -12 VDC.

AVR as DTE ("master")

RTS/CTS handshake requires the DTE (pc, terminal) to request to send (RTS) and wait for the DCE (modem or other device) to assert clear to send (CTS) before actually sending the data. It does not provide handshaking the other direction. That is generally implemented using data terminal ready (DTR) to hold off the modem until the DTE is ready to accept data. There is no request-response handshake, the modem just needs to verify that the DTE is there and ready.

The following flowchart shows the minimum requirement for RTS/CTS handshake from the point of view of a DTE. Keep in mind that the time between the assertion of RTS and the receipt of CTS may be a minimum of 50mS.

In the real world, you need to have a timer flag in the "wait for CTS" path, or you won't get much done when the cable is unplugged.

AVR as DCE ("slave")

When the AVR is acting as a DCE (modem, etc), it will be receiving the RTS signal from the DTE and will respond with CTS given the following:

If all of these things are true, the AVR would assert CTS (logic "0").