title: Arduino Serial Interrupts
body: <p>I am working on an Arduino Mega 2560 project. At a Windows 7 PC I am using the Arduino1.0 IDE. I need to establish a serial Bluetooth communication with a baud rate of 115200.  I need to receive an interrupt when data is available at RX. Every piece of code I have seen use “polling”, which is placing a condition of Serial.available inside Arduino’s loop. How can I replace this approach at Arduino’s loop for an Interrupt and its Service Routine? It seems that attachInterrupt() does not provides for this purpose.  I depend on an Interrupt to awake the Arduino from sleep mode.</p>
  
  <p>I have developed this simple code that is supposed to turn on a LED connected to the pin 13.  </p>
  
  <pre><code>    #include &lt;avr/interrupt.h&gt; 
      #include &lt;avr/io.h&gt; 
      void setup()
      {
         pinMode(13, OUTPUT);     //Set pin 13 as output
  
         UBRR0H = 0;//(BAUD_PRESCALE &gt;&gt; 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register 
         UBRR0L = 8; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register 
         UCSR0C |= (1 &lt;&lt; UCSZ00) | (1 &lt;&lt; UCSZ10); // Use 8-bit character sizes 
         UCSR0B |= (1 &lt;&lt; RXEN0) | (1 &lt;&lt; TXEN0) | (1 &lt;&lt; RXCIE0);   // Turn on the transmission, reception, and Receive interrupt      
      }
  
      void loop()
      {
        //Do nothing
      }
  
      ISR(USART0_RXC_vect)
      {    
        digitalWrite(13, HIGH);   // Turn the LED on          
      }
  </code></pre>
  
  <p>The problem is that the subroutine is never served.</p>