AVR 40 pin proto board RS232 incorrect?

Hi Folks,

I have a couple of the Olimex 40 pin AVR proto boards and am trying to hook up the RS232 port and I’m trying to figure out how to reconcile the Olimex schematic and the MAX232 schematic.

The Olimex schematic has the RX pin connected to pin 10 of the MAX232 chip which is the T2in according to the MAX232 datasheet. Shouldn’t it be connected to pin 12 which is R1out?

Thanks,

Richard Cooke

Hi Richard,

It’s all just a matter of perspective; the one used here is from the max232. With the Olimex boards, hook the Rx from your micro to the Tx of the Max, and the Tx of the micro to the Rx of the Max chip. Admittedly, it takes getting use to.

Regards,

Robert

Thanks for the answer. It still doesn’t make sense but I’ll try it TX0 on the Atmega32 chip connected to the RX1out pin on the MAX232 chip.

Do you happen to know where to get a simple UART test program that justs sends out a “hello world”(or similar)?

Hi,

AVR is not my forte, and you haven’t said which language or tools you are using, however I did find an example in assembly. Here is the discription and a link:

Description :

The program fetches the string “Hello World” in the program memory and send it to Hyperterminal screen via UART. To me, I have learned how to make use of the content Stack pointers pointing to the next location after the call instruction by writing and experimenting it. You can learn it from reading the design notes of it or stimulating and trying my sample program with STK500 board. I hopes it may be helpful to you.

Nay Oo

Found on AVR Freaks here:

http://www.avrfreaks.net/index.php?modu … tem_id=192

You may need to register to get to this code though. If you have trouble let me know and I’ll post the entire source. I hope this is what you were looking for, or perhaps someone else who is good at AVR can jump in here.

Regards,

Robert

Hi,

I should have remembered to post the particulars of my chip/software.

I’m using the ATmega32 on the Sparkfun 40 pin development board. I’m using the AtmanAVR IDE/GCC combo since I’m much more comfortable with C than asm.

Thanks,

Richard

Hi,

Then check the install directory of your tools, there may be some sample source in there, as this is a pretty basic project. You may also find source for this on AVR freaks, and it would be worth joining if you use AVRs.

Regards,

Robert

Wow, this is a late reply, but what the heck… it’ll help anyone else who needs it eventually. I’m posting mainly because I just got the AVR-P40 myself in the mail yesterday and was tinkering with it today.

Regarding the physical wiring, it’s a little off simply because of how they wired up the other side of the MAX232 chip, but it all makes sense after a while. Pin 2 and 3 on the serial cable are for send and recieve, respectively, so you just have to follow that. In the end, you have to connect the AVR’s TxD (PD1 pin 15) to T2IN (Pin 10), and RxD (PD0 pin 14) to R1OUT (Pin 12). Confusing, but it works.

Also, be sure to turn off all flow control if you have the option on the other end of the connection (i.e. hyperterminal). Took me a while to figure it out because you can leave Hardware flow control on and still communicate with the STK500. Never thought to check it till after an hour :oops:.

For the code, I have a simple sample I made for the ATMega16/32. This will work with AVRStudio and GCC:

main.c

#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include "sci.h"


int
main(void)
{
	unsigned char * blah = "Hello there.\n\r";

	DDRB = 0x01; // Sink LED indicator on Olimex Board

	init_SCI();
	sei();

	outString(blah);
	

	MCUCR = _BV(SE); /* Idle mode. Wake up for interrupts/IO */
	while(1) {
		asm(" SLEEP\n");
	}

	return 0;
}

EMPTY_INTERRUPT(__vector_default)

sci.c

#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include "sci.h"

#ifndef __B_RATE
	#define __B_RATE 9600
#endif

/* Calculation for prescaler. Define F_CPU in Makefile. */
#define __UBRRH_BAUD (F_CPU/16/__B_RATE-1)

/* volatile or else gcc optimizations won't properly create the while loops */
volatile unsigned char TxBuffer, RxBuffer;


void
outString(unsigned char * input)
{
	unsigned int i = 0;
	while(input[i])
		putChar(input[i++]);
}

void
putChar(unsigned char input)
{
	while(TxBuffer != 0);
	TxBuffer = input;
	UCSRB |= _BV(UDRIE);
}

unsigned char
getChar(void)
{
	unsigned char temp;
	while(RxBuffer == 0);
	temp = RxBuffer;
	RxBuffer = 0;
	return temp;
}

unsigned char
currentChar(void)
{
	return RxBuffer;
}

void
init_SCI(void)
{
	/* Set Baud Rate. */
	UBRRH = (unsigned char)(__UBRRH_BAUD>>8);
	UBRRL = (unsigned char)(__UBRRH_BAUD);

	/* Enable Rx and Tx, and interrupt */
	UCSRB = _BV(RXCIE) | _BV(RXEN) | _BV(TXEN);

	/* Frame Format - 8 data, no parity */
	/* NEED URSEL FOR MEGA16/32 */
	UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);
}

SIGNAL(SIG_USART_RECV)
{
	RxBuffer = UDR;
	putChar(RxBuffer);
}


SIGNAL(SIG_USART_DATA)
{
	if(TxBuffer == 0)
		UCSRB &= ~_BV(UDRIE);
	else
		UDR = TxBuffer;
	TxBuffer = 0;
}

sci.h

#ifndef _SCI_H
#define _SCI_H

#define __B_RATE 9600

void init_SCI(void);
void outString(unsigned char *);
void putChar(unsigned char);
unsigned char getChar(void);
unsigned char currentChar(void);

#endif

I looks like that code’s interrupt handlers just save the last character than was received - rather than store them in a ring buffer.

On avrfreaks.net there are quite a few donated buffered serial I/O handlers you could use more or less as-is. And some/most integrate with the C library so they’ll support the library buffered I/O for printf() et al.

One that I contributed is

http://www.avrfreaks.net/index.php?modu … pe=project

cheers