Arduino Sequential Interrupts

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);     //Set pin 13 as output

       UBRR0H = 0;//(BAUD_PRESCALE >> 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 << UCSZ00) | (1 << UCSZ10); // Use 8-bit character sizes 
       UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);   // Turn on the transmission, reception, and Receive interrupt      
    }

    void loop()
    {
      //Do nothing
    }

    ISR(USART0_RXC_vect)
    {    
      digitalWrite(13, HIGH);   // Turn the LED on          
    }

The problem is that the routine is never served.

+5
3

, . "USART0_RXC_vect" USART0_RX_vect. interrupts();, , .

:

#include <avr/interrupt.h> 
#include <avr/io.h> 
void setup()
{
   pinMode(13, OUTPUT); 

   UBRR0H = 0; // 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 << UCSZ00) | (1 << UCSZ10); // Use 8-bit character sizes 
   UCSR0B |= (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);   // Turn on the transmission, reception, and Receive interrupt      
   interrupts();
}

void loop()
{

}

ISR(USART0_RX_vect)
{  
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
}

!!!!

+6

, ? , , . sei(); interrupts(); setup.

+1

Immediately after UBRR0L = 8instead:

 UCSR0C |= (1 << UCSZ00) | (1 << UCSZ01);

change to this:

 UCSR0C |= (1 << UCSZ00) | (1 << UCSZ10);
0
source

All Articles