title: Use Hardware RX pin as an interrupt pin of arduino
body: <p>I want to use hardware RX pin of Arduino as interrupt pin. If there is any data available on RX pin, an interrupt signal will be generated, call a callback function to read incoming serial data.I don't want my loop() function constant reading on serial port. I am using this code but my interrupt is not triggered.I also tried by removing digitalPintointerrupt() but getting no response.</p>
  
  <pre><code>`#include &lt;SoftwareSerial.h&gt;
  const byte interruptPin = 0;//In arduino MEGA RX 19. TX 18
  String msg = "";//Incomming message
  #define Line_RX 3 //UART RX
  #define Line_TX 2 //UART TX
  
  SoftwareSerial mySerial (Line_TX, Line_RX); //initialize software serial
  
  void setup() {
    // put your setup code here, to run once:
    Serial.begin(19200);
    mySerial.begin(19200);
    attachInterrupt(digitalPinToInterrupt(interruptPin), serial_read, HIGH);
  }//end setup
  
  void loop() {
    // put your main code here, to run repeatedly:
  }//end loop
  
  void serial_read(){
  
    char _bite;
    sei();//Disable hardware interrupts for a moment
    while(Serial.available()&gt;0){
      delay(1);//Do not delete this delay
      if(Serial.available()&gt;0){
        _bite = (char)Serial.read();
        msg += _bite;
        if(_bite == '\n'){
         mySerial.print(msg);//Do what you print your message
          msg = "";//Clean message for new one
          break;
        }//end if
      }//end if
    }//end while
    cli();//re-enabling hardware interrupts
  }//en
  </code></pre>
  
  <p>d serial_read`</p>