シリアルモニタでの印刷にUSART0を使用しているので、USARTモジュール1の受信完了割り込み(ISR)を使用してArduino MEGA2560のUSARTデータを受信する次のコードを記述しました。 MEGAはESP8266 WiFiモジュールとインタフェースしているため、初期化のためにATコマンドを送信した後、割り込み()がセットされています! 問題は、私が得ることです:私は、最新のIDE(0.12版)を使用して、ここのコードでいArduino MEGAのエラーステータス1
「のArduino/GenuinoののMEGA用にコンパイルする1 エラー終了ステータス」。
#include <avr/interrupt.h>
#include <avr/io.h>
#define F_CPU 16000000UL
#define BAUDRATE 9600
#define BAUD_PRESCALER (((F_CPU/(BAUDRATE * 16UL))) - 1)
volatile int i=0;
volatile uint8_t buff[6];
volatile uint8_t StrRxFlag=0;
void setup() {
// put your setup code here, to run once:
Serial1.begin(9600);
Serial.begin(9600);
USART_INIT();
reset();
client_set();
}
void USART_INIT(void)
{
cli();
UBRR1 = BAUD_PRESCALER; // Set the baud rate prescale rate register
UCSR1B = ((1<<RXEN1)|(1<<TXEN1)|(1 << RXCIE1)); // Enable receiver and transmitter and Rx interrupt
UCSR1C = ((0<<USBS1)|(1 << UCSZ11)|(1<<UCSZ10)); // Set frame format: 8data, 1 stop bit. See Table 22-7 for details
}
void reset()
{
Serial1.println("AT");
if(Serial1.find("OK")) Serial.println("The module is fine");
}
void client_set()
{
char a;
Serial1.println("AT+CWMODE=2");
delay(1000);
while(Serial1.available())
{
a = Serial1.read();
Serial.print(a);
}
Serial1.print("AT+CWJAP=\"new\",\"123\"");
//delay(2000);
while(Serial1.available())
{
a = Serial1.read();
Serial.print(a);
}
Serial1.print("AT+CIFSR");
//delay(1000);
while(Serial1.available())
{
a=Serial1.read();
Serial.print(a);
}
Serial1.print("AT+CIPSERVER=1");
//delay(1000);
while(Serial1.available())
{
a=Serial1.read();
Serial.print(a);
}
interrupts();
}
void loop() {
}
ISR(USART1_RX_vect)
{
buff[i]=UDR1; //Read USART data register
if(buff[i++]=='\r') //check for carriage return terminator and increment buffer index
{
// if terminator detected
if(buff[i]=='\n')
{
StrRxFlag=1; //Set String received flag
buff[i-1]=0x00; //Set string terminator to 0x00
Serial.println("Received data is");
for(int j=0; j<sizeof(buff);j++)
{
Serial.print(buff[j]);
}
i=0; //Reset buffer index
}
}
}
関連性のないSerial1を使用しているATコマンドの送信は無視してください。私は、割り込み(ISR)とそれに関連するものの使用に間違いがないかどうかを知りたい。
コンパイル後にIDEレスポンスを添付しています。前もって感謝します!