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);
}