# problem in serial communication between PC and ATMEGA 8535(AVR)

I have written code to send data from controller to pc through serialport using interrupt but it echos garbage value exactly 3 times back.

    ISR(USART_RX_vect)
{
unsigned char index = UDR;

UDR = index;
}

void uartInit()
{
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x67;
UCSRB |= (1 << RXCIE); // Enable the USART Receive Complete interrupt (USART_RXC)
_delay_ms(10);
}

int main(void)
{
uartInit();
lcd_init();
sei();

while(1)
{
}
}


EDIT: Function used to set baud rate..

#define FOSC 16000000// Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1

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

• This frequently a result of the client baud rate being set incorrectly. – DaemonMaker Feb 27 '13 at 22:01
• How exactly are you connecting your AVR to the PC? I assume you have a TTL-RS232 tranceiver setup with an IC such as the MAX232. Is that so? – georgebrindeiro Feb 28 '13 at 1:39
• yes thats how it is connected. – amitkindre Feb 28 '13 at 9:35
• @DaemonMaker - When there isn't enough information in the question to determine if a suggestion like this is an answer or not, it's probably best making a comment asking for clarification rather than posting a one line answer which may or may not be relevant. – Mark Booth Feb 28 '13 at 12:51
• @DaemonMaker - I agree that there is a possibility that this is the reason and hopefully the edit will provide enough information for someone to answer the question authoritatively. – Mark Booth Feb 28 '13 at 19:43