Help! Interrupt USART arduino mega2560

Hello everybody, I'm programming a function , this having USART interface.But i can't using interrupt when RX complete.
Please help me!

#include <avr/io.h>
#include <avr/interrupt.h>
volatile unsigned char Data;
void setup(){
  Serial.begin(9600);
  UBRR2H=0x00;
  UBRR2L=0x67; // baurate=9600, F=16Mhz , no X2
  UCSR2A = 0x00;
  UCSR2B |= (1<<RXEN2)|(1<<TXEN2)|(RXCIE2);
  UCSR2C = (1<<UCSZ21)|(1<<UCSZ20); //8bit data+1stop
  sei ();
}

void loop(){ 

}
ISR(USART2_RXC_vect){
Data=UDR2;
Serial.print(Data);
}

Why are you not using Serial2?

because , after serial2 receiver after sended complete 1 byte to another arduino mega 2560
if i using:

if(Serial2.available()){
//receiver data

}

i don't know when data come.

please help me!

Re: Help! Interrupt USART arduino mega2560 #2
Today at 08:17 pm Last Edit: Today at 08:17 pm by maichanduy

Re: Help! Interrupt USART arduino mega2560 #3
Today at 08:35 pm

please help me!

It is certainly sad that you didn't get a response after 18 minutes. Would you like me to complain to the Management for you?

How to use this forum

maichanduy:
if i using:

if(Serial2.available()){
//receiver data

}

i don't know when data come.

If you don't know when the data arrives it is because your code is not checking the serial port often enough which suggests that other parts of your program are poorly organized.

An Arduino can check the serial ports much faster than the serial ports can receive data.

Look at the Arduino code in this demo

...R