#define ME
Newbie level 2
- Joined
- Jun 20, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 15
Hi everyone, can somebody show me or guide me how to receive and transmit a complete string using interrupt, after this I using polling. My code is like this --->:arrow:
But it does not came out the whole string, it only take 4 letter. e.g. I wrote ABCDEF it come out ABCF ,:-? that why I want to use interrupt. Can someone show me the code or guide me about this. I am using avr studio 5 and bray terminal like this one.
Thank for the help :grin:
Code:
#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;
}
But it does not came out the whole string, it only take 4 letter. e.g. I wrote ABCDEF it come out ABCF ,:-? that why I want to use interrupt. Can someone show me the code or guide me about this. I am using avr studio 5 and bray terminal like this one.
Thank for the help :grin: