How to received string in uart. I am using avr studio 5 and brays terminal like this one
Same as this picture I am using baudrate of 9600. Went I try to type "abcdef"
, it only come out "abcf"
.
My code are like this --->
#include <avr/io.h>
void serial_init(void)
{
UBRRH = 0x00;
UBRRL = 95; //baudrate 9600 and F_CPU 14745600UL
UCSRB = (1 << RXEN) | (1 << TXEN) | (1<<RXCIE);
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0)|(1 << UCSZ1);
}
unsigned long long Usart_Receive(void)
{
while((UCSRA & (1 << RXC)) == 0) {};
return UDR;
}
void USART_Transmit(unsigned long c)
{
PORTD= 0b00000100; //RTS Enable
while ((UCSRA & (1 << UDRE)) ==0) {};
UDR = c;
PORTD= 0b00000000; //RTS Disable
}
int main(void)
{
unsigned char data;
serial_init();
while (1)
{
data = Usart_Receive();
_delay_ms(100);
USART_Transmit(data);
}
return 0;
}
Simple as that, but I cannot find my problem why it only appear 4 letter at the terminal. I hope somebody can help about this. THANK.
Here are the answer that are work.
Thank for those who are helping me before this.