小编beb*_*_lm的帖子

Arduino串行中断

我正在研究Arduino Mega 2560项目.在Windows 7 PC上,我使用的是Arduino1.0 IDE.我需要建立一个波特率为115200的串行蓝牙通信.当RX上的数据可用时,我需要接收一个中断.我见过的每一段代码都使用"轮询",这是在Arduino循环中放置Serial.available的条件.如何在Arduino的循环中替换这种方法以获得中断及其服务程序?似乎attachInterrupt()没有提供此目的.我依靠中断从睡眠模式中唤醒Arduino.

我开发了这个简单的代码,它应该打开连接到引脚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 …
Run Code Online (Sandbox Code Playgroud)

microcontroller bluetooth arduino interrupt serial-communication

5
推荐指数
1
解决办法
2万
查看次数