I am working on an Arduino Mega 2560 project. On a Windows 7 PC, I am using the Arduino1.0 IDE. I need to establish a Bluetooth serial connection with a baud rate of 115200. I need to get an interrupt when data is available in RX. Each piece of code I've seen uses a “poll” that places a Serial.available condition inside an Arduinos loop. How can I replace this approach with an Arduinos loop for interrupt and its service procedure? AttachInterrupt () does not seem to provide for this purpose. I rely on interruption to wake Arduino in sleep mode.
I developed this simple code that should turn on the LED connected to pin 13.
#include <avr/interrupt.h>
#include <avr/io.h>
void setup()
{
pinMode(13, OUTPUT);
UBRR0H = 0;
UBRR0L = 8;
UCSR0C |= (1 << UCSZ00) | (1 << UCSZ10);
UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
}
void loop()
{
}
ISR(USART0_RXC_vect)
{
digitalWrite(13, HIGH);
}
The problem is that the routine is never served.