kevinzhang 发表于 2014-9-12 13:03:38

Super169 发表于 2014-9-12 11:55 static/image/common/back.gif
oh, 即是說, arduino.cc 中, 對 mega 的 interrupt 描述有錯 (跟 pin mapping 不同)?

http://arduin ...

:handshake:handshake:handshake

kevinzhang 发表于 2014-9-14 19:11:30

Super169 发表于 2014-9-12 11:55 static/image/common/back.gif
oh, 即是說, arduino.cc 中, 對 mega 的 interrupt 描述有錯 (跟 pin mapping 不同)?

http://arduin ...

Super,您老测试得咋样啊?:loveliness::handshake

Super169 发表于 2014-9-14 20:58:44

kevinzhang 发表于 2014-9-14 19:11 static/image/common/back.gif
Super,您老测试得咋样啊?

Sorry, 試完唔記得 post 出黎添....因為我已經知道答案.:lol

我既測試好簡單, 用左一塊 Uno 同埋一塊 Mega 版.
首先共地, GND 同 GND 駁埋.
之後 Uno 既 pin 7 接 Mega 既 pin 2, 然後做左兩個簡單 program:

1) Uno - 不斷改變 pin 7, HIGH - LOW 轉黎轉去.3秒一次

void setup() {
Serial.begin(57600);
pinMode(7, OUTPUT);
}

void loop() {
Serial.println("Set to HIGH");
digitalWrite(7, HIGH);
delay(3000);
Serial.println("Set to LOW");
digitalWrite(7, LOW);
delay(3000);
}


2) Mega: 做左個 counter, 每次 Int.0 被 trigger (有變動) 就加 1, 每秒 check1 次.

int change_cnt = 0;

void setup() {
Serial.begin(57600);
attachInterrupt(0, pin_change, CHANGE);
}

void loop() {
// put your main code here, to run repeatedly:
Serial.println(change_cnt);
delay(1000);
}

void pin_change() {
change_cnt++;
}


結果, 當 Uno 轉既時候, Mega 果邊既數字就會加 1.由於 Mega 每秒 check 一次, 結果每出三次同一個數就加 1.

由於佢講到 Mega 既 Int.0 好似去左 pin 10, 我又試埋將 Uno Pin 7 接 Mega Pin 10, 結果當然係完全唔變喇.


結果好明顯, Mega 既 Int.0 係 map 去 Pin 2 的, 即係 arduino 入面, 對 Mega 既描述無錯, 而 attachInterrupt 既表亦無錯的.

咁真係唔明, 點解佢話 pin 2 無 interrupt 了.

kevinzhang 发表于 2014-9-14 22:28:44

Super169 发表于 2014-9-14 20:58 static/image/common/back.gif
Sorry, 試完唔記得 post 出黎添....因為我已經知道答案.

我既測試好簡單, 用左一塊 Uno 同埋一塊...

:dizzy::dizzy::dizzy:

kevinzhang 发表于 2014-9-14 22:29:02

Super169 发表于 2014-9-14 20:58 static/image/common/back.gif
Sorry, 試完唔記得 post 出黎添....因為我已經知道答案.

我既測試好簡單, 用左一塊 Uno 同埋一塊...

:dizzy::dizzy::dizzy:

eddiewwm 发表于 2014-9-15 23:47:46

本帖最后由 eddiewwm 于 2014-9-15 23:51 编辑

Super169 发表于 2014-9-14 20:58 static/image/common/back.gif
Sorry, 試完唔記得 post 出黎添....因為我已經知道答案.

我既測試好簡單, 用左一塊 Uno 同埋一塊...

噢,一路都沒注意到 Mega 的 External Interrupts 又 re-map 了。

原作者想說的是 Pin Change Interrupt,而不是 External Interrupt,所以 The Leonardo and Mega do not have interrupt capabilities on pin 2 是對的。

當中重點是: "Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)"
http://arduino.cc/en/Reference/SoftwareSerial

kevinzhang 发表于 2014-9-16 06:28:28

eddiewwm 发表于 2014-9-15 23:47 static/image/common/back.gif
噢,一路都沒注意到 Mega 的 External Interrupts 又 re-map 了。

原作者想說的是 Pin Change Inter ...

:handshake:handshake:victory:
页: 1 [2]
查看完整版本: How to use the GSM shield with Arduino Leonardo and Arduino Mega