我正在开发一个Arduino Mega 2560项目。在Windows 7 PC上,我使用Arduino1.0 IDE。我需要建立一个波特率为115200的串行蓝牙通信。当RX有数据可用时,我需要接收中断。我看到的所有代码都使用“轮询”,即将Serial.available条件放置在Arduino的循环内。如何用中断及其服务例程替换Arduino循环中的这种方法?似乎attachInterrupt()不能提供此目的。我依赖于中断来唤醒Arduino从睡眠模式中醒来。
我已经开发了这个简单的代码,它应该打开连接到13号引脚的LED灯。
问题在于子程序从未被调用。
我已经开发了这个简单的代码,它应该打开连接到13号引脚的LED灯。
#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
}
问题在于子程序从未被调用。