[AVR] Make String Interrupt

Status
Not open for further replies.

#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:

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:
 

Put your receive code inside
Code:
ISR USART_RC_Vect()  {

}

and enable Serial and global interrupts before while(1).
 

thank for this guide, but I already know what interrupt opening but what's in the middle that I did not know what to put to make sure that it receive a complete string.

Code:
void serial_init(void)
{
	UBRRH = 0x00;
	UBRRL = 95;
	UCSRB =  (1 << RXEN) | (1 << TXEN) | [B][I](1<<RXCIE)[/I][/B]; 
	UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0)|(1 << UCSZ1); 
	
}

ISR (USART_RXC_vect)
{ 
//I dont know what to put

}

before this I already try this interrupt
Code:
ISR(USART_RXC_vect) 
{ 
   char ReceivedByte; 
   ReceivedByte = UDR; // Fetch the received byte value into the variable "ByteReceived" 
   UDR = ReceivedByte; // Echo back the received byte back to the computer 
}

but it only sent and receive a character. How to modified this code to enable it to send a string. :smile:
Thank.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…