Need help with Serial Port

Started by Rakesh Kumar February 9, 2007
Hey,

I was wanting to do the serial communication with my atmega32. I am using
the 1 MHz internal oscillator. The baud rate calculation gives up 2400 bps.
Here's the code I am using for simply echoing back the character typed in
the Hyper Terminal.

/*this program is to test the microcontroller uart working or not by sending
0x99 to the
uart and reading it using Rx and sending it to port. Change the Port to
PortA or PortB if
you had not disabled JTAG
*/

/*----------------------------
-----------------HEADER FILES-
-----------------------------*/
#include

/*----------------------------
-----------------DEFINITIONS
-----------------------------*/

#define Receive_DDR DDRC
#define Receive_PORT PORTC //don't forget to disable JTAG, otherwise change
port to PORTB or PORTA
/*----------------------------
-----------------FUNCTIONS---
-----------------------------*/

void InitUART( unsigned char baudrate );
unsigned char ReceiveByte( void );
void TransmitByte( unsigned char data );
void Init_Ports(void);

/*----------------------------
-----------------MAIN FUNCTION
-----------------------------*/

int main()
{
unsigned char a;
//lcd initializationsa
Init_Ports();

InitUART( 25 ); /* Set the baudrate to 2400 bps using a 1MHz crystal */
for(;;) /* Forever */
{

TransmitByte(0x99); /* Echo the received character */
Receive_PORT=ReceiveByte();

}

}

/*----------------------------
------------FUNCTIONS TO Initialize UART--------------------------
-----------------------------*/

void InitUART( unsigned char baudrate )
{
UBRRL = baudrate; /* Set the baud rate */
UCSRB = (UCSRB | _BV(RXEN) | _BV(TXEN) ); /* Enable UART receiver and
transmitter */
}
/*----------------------------
------------FUNCTIONS TO READ UART-------------------------------
-----------------------------*/
unsigned char ReceiveByte( void )
{
while ( !(UCSRA & (_BV(RXC))) ); /* Wait for incomming data */
return UDR;/* Return the data */
}

/*----------------------------
------------FUNCTIONS TO WRITE UART-------------------------------
-----------------------------*/
void TransmitByte( unsigned char data )
{
while ( !(UCSRA & (_BV(UDRE))) ); /* Wait for empty transmit
buffer */
UDR = data; /* Start transmittion */
}

void Init_Ports(void)
{
Receive_DDR=0xFF; //setting that port for output
Receive_PORT=0XFF; //setting all bits high for starting
}
--------

I am using the schematic as given in the Bibin John's AVR book. I have
verified the MAX232 connections from the data-sheet. Checked for
short-circuits.

What happens is that no matter what key I press, I get this down arrow sort
of symbol in the response to it. Any inputs on what might be causing the
problem?

--
Rakesh.
http://gopchandani.wordpress.com