SmaTrig 2.1

Compact RS232 to TTL converter

Update: There is a new low voltage version of the MAX232 called MAX3232. I updated my converter revently and it works fine with 3V from two batteries now.

RS232 to TTL converter

When programming microcontrollers debugging is inevitable. Options like JTAG or DebugWIRE exist, but they are usually too expensive for most entry level DIYers. Another simple and controller-independent option is to utilise the USART for debugging. It's integrated into nearly all of today's microcontrollers. The only problem here is to convert the two serial signals RXD and TXD from the controller levels, usually TTL, to the EIA-232 levels as found in the serial port of every PC. Fortunately there is the MAX232, which converts signals between both levels.

This article describes how to build an extremely compact converter circuit built around the MAX232. With a size of just 14 x 17 mm (0.55 x 0.67 inch) the PCB is small enough to fit into a D-SUB plug housing as shown in the title picture above. When designing a new AVR circuit you just have to connect the converter to the AVR and you're ready to communicate in both directions.

The circuit is shown in the images below. It's a standard application of the MAX232, the only point worth mentioning is that the thin SO16 version of the MAX232 was used in the PCB layout. There are alternative versions of the original Maxim chip, e.g. from TI (also named MAX232) or ST called ST232 (my favourite). They are usually cheaper then the Maxim equivalents. Some older MAX232 versions need 1 uF capacitors instead of 100 nF required by the newer types. All five caps on the PCB are 0805 SMD packages. The prototype PCB shown in the first picture is mirrored because of a stupid fault, however all files provided for download below are correct.

rs232 converter pcb and coin rs232 converter schematics rs232 converter board

At this point I'd like to mention that soldering SMD parts is not as difficult as it might seem. It doesn't require any special motor skills. All you need is a soldering iron with a sharp tip and thin solder!

Example code

The source code below can be used to test the proper functioning of the converter. It sends the string 'hello' to the serial port and then echos back all characters send to the controller. It is based on the code snippets given in the ATmega8 data sheet. The USART settings in the code below are:

  • 38400 baud/s data rate
  • 8 data bits
  • 1 stop bit
  • no parity bits
#define F_CPU 8000000dontforgettochange
#define BAUD 38400
#define MYUBRR F_CPU/16/BAUD-1

#include <stdlib.h>
#include <avr/io.h>

void USART_Init( unsigned int ubrr)
{
	/* Set baud rate */
	UBRRH = (unsigned char)(ubrr>>8);
	UBRRL = (unsigned char)ubrr;
	/* Enable receiver and transmitter */
	UCSRB = (1<<RXEN)|(1<<TXEN);
	/* Set frame format: 8data, 2stop bit */
	UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}

void USART_Transmit( unsigned char data )
{
	/* Wait for empty transmit buffer */
	while ( !( UCSRA & (1<<UDRE)) )
	;
	/* Put data into buffer, sends the data */
	UDR = data;
}

unsigned char USART_Receive( void )
{
	/* Wait for data to be received */
	while ( !(UCSRA & (1<<RXC)) )
	;
	/* Get and return received data from buffer */
	return UDR;
}

int main(void) 
{
	unsigned char data;

	USART_Init ( MYUBRR );

	USART_Transmit('h');
	USART_Transmit('e');
	USART_Transmit('l');
	USART_Transmit('l');
	USART_Transmit('o');

	for(;;)
	{
		data = USART_Receive();
		USART_Transmit(data);
	}
}

There is a variety of terminal programs for serial communication. HyperTerminal is included in Windows, HTerm or Br@y++ Terminal are good alternatives. Don't forget to deactivate all protocols (flow control: none) when sending data to the controller.

Download

All files necessary to build the converter are provided below. If the given PCB layout doesn't fit into your plug, use the Eagle files to rearrange the parts as necessary.

rs232plug_layout.pdf - PCB layout
rs232plug.sch - Eeagle schematics
rs232plug.brd - Eeagle board
rs232.c - Example C code

Happy communicating!

Links

http://www.st.com/stonline/products/literature/ds/6420/st232c.pdf
ST232 data sheet

http://en.wikipedia.org/wiki/RS-232
Article about RS-232 in Wikipedia

http://www.der-hammer.info/terminal/
HTerm - a nice and compact terminal program

http://braypp.googlepages.com/terminal
Br@y++ Terminal - another terminal program

Comments (9)

Re:
I propose not to hold back until you get big sum of cash to buy goods! You can just get the home loans or just short term loan and feel comfortable
#9 - RamirezHelene33 - 01/21/2013 - 07:49
nike shoes wholesale
only to eat a lockout. Amanda Bynes says: "I'm not a a good guy, my goal is to help Everton to return to Europe playing field and win a Championship. ”
#8 - nike shoes wholesale - 09/08/2012 - 02:29
I've buy from usa via http://www.nybox.com
#7 - converter - 10/21/2011 - 01:02
Voltage output
Hi,
can you tell me the output voltage of the rs232 tx,rx
#6 - Vishwanath - 05/12/2011 - 08:32
USB to TTL cable is even more compact for debugging
In the UK you can buy cheap RS232 to TTL kits from Tronisoft
http://www.tronisoft.com/cat_rs232tottl.php

or USB to TTL cables
http://www.tronisoft.com/cat_usbtottl.php

USB to TTL is great for debugging from PICs or ATMEL devices if your Laptop does not have a serial port.

Joe

#5 - Joe Marne - 01/28/2011 - 13:26
Very elegant design!
#4 - Luk - 05/20/2010 - 08:25
Nice
Not long ago I've built a very similar converter

Can be seen at http://www.eercz.com

regards
#3 - rolocz - 05/18/2010 - 07:33
Nice tips, your blog impress me !
#2 - play65 - 12/02/2009 - 23:43
Cheers mate
Thanks so much for these tips on how to build an extremely compact converter circuit built around the MAX232. I have been tinkering about with these sorts of things for a while but I'm still a real newbie really.
#1 - Brendan - 11/29/2009 - 15:25
Name
E-mail (Will not appear online)
Homepage
Title
Comment
To prevent automated Bots form spamming, please enter the text you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
»
This comment form is powered by GentleSource Comment Script. It can be included in PHP or HTML files and allows visitors to leave comments on the website.

PHP Script   Throwaway Email   Throwaway Email