5

Arduino Mega 2560 projesinde çalışıyorum. Windows 7 PC'de Arduino1.0 IDE kullanıyorum. 115200 baud hızı ile bir seri Bluetooth iletişimi kurmam gerekiyor. RX'de veri mevcut olduğunda bir kesme almam gerekiyor. Arduino’nun döngüsünde Serial.available’i belirten “yoklama” yı kullandığım her kod parçası. Bu yaklaşımı Arduino’nun bir Interrupt ve Servis Rutinindeki döngüsünde nasıl değiştirebilirim? AttachInterrupt() bu amaç için sağlanmamış gibi görünüyor. Arduino'yu uyku modundan uyandırmak için bir Interrupt'a bağlıyım.Arduino Seri Kesmeler

Ben pimi 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   
    } 

sorun altyordamı hiç yayınlanmadı olmasıdır bağlı bir LED açmak gerekiyordu bu basit kod geliştirdik.

+0

Sorunuzun bluetooth ile ne ilgisi var? Düzenli bir UART'ın nasıl kesinti yapılacağını soruyormuş gibi mi görünüyorsun? – TJD

cevap

6

Sonunda sorunumu buldum. "USART0_RXC_vect" kesinti vektörünü USART0_RX_vect ile değiştirdim. Ayrıca global interrupt'ı etkinleştirmek için interrupts(); ekledim ve çok iyi çalışıyor.

kodudur: Cevaplar için

#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 
} 

Teşekkür !!!!

1

Bu kodu denediniz mi ve işe yaramadı mı? Sorun şu ki, ara vermediniz. setup işlevinizde sei(); veya interrupts(); numaralı telefonu çağırmayı deneyebilirsiniz.