Skip to content

Commit bfc70f2

Browse files
wangcoolcPillar1989
authored andcommitted
Modified put the receive interrupt before begin
1 parent 3c78368 commit bfc70f2

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

examples/receive_interrupt/receive_interrupt.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void setup() {
4242
while (!SERIAL) {
4343
; // wait for serial port to connect. Needed for native USB port only
4444
}
45+
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
4546
#ifdef CAN_2518FD
4647
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
4748
#else
@@ -52,8 +53,8 @@ void setup() {
5253
delay(100);
5354
}
5455
SERIAL.println("CAN BUS Shield init ok!");
55-
pinMode(CAN_INT_PIN, INPUT);
56-
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
56+
delay(100);
57+
5758
}
5859

5960
void MCP2515_ISR() {

examples/receive_interruptFD/receive_interruptFD.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void setup() {
3333
while (!SERIAL) {
3434
; // wait for serial port to connect. Needed for native USB port only
3535
}
36+
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
3637
CAN.setMode(0);
3738
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
3839
SERIAL.println("CAN BUS Shield init fail");
@@ -43,8 +44,6 @@ void setup() {
4344
SERIAL.printf("CAN BUS get mode = %d\n\r",mode);
4445
SERIAL.println("CAN BUS Shield init ok!");
4546
SERIAL.println("CAN BUS Shield init ok!");
46-
pinMode(CAN_INT_PIN, INPUT);
47-
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
4847
}
4948

5049
void MCP2515_ISR() {

examples/recv_sd/recv_sd.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ char str[20];
4242

4343
void setup() {
4444
SERIAL.begin(115200);
45-
45+
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
4646
#ifdef CAN_2518FD
4747
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
4848
#else
@@ -53,9 +53,7 @@ void setup() {
5353
delay(100);
5454
}
5555
SERIAL.println("CAN BUS Shield init ok!");
56-
57-
attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
58-
56+
5957
if (!SD.begin(4)) {
6058
SERIAL.println("SD initialization failed!");
6159
while (1);

examples/set_mask_filter_recv/set_mask_filter_recv.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ char str[20];
3838
void setup() {
3939
SERIAL.begin(115200);
4040
while(!Serial){};
41-
41+
attachInterrupt(digitalPinToInterrupt(interruptPin), MCP2515_ISR, FALLING); // start interrupt
4242
#ifdef CAN_2518FD
4343
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
4444
#else
@@ -50,9 +50,6 @@ void setup() {
5050
}
5151
SERIAL.println("CAN BUS Shield init ok!");
5252

53-
attachInterrupt(digitalPinToInterrupt(interruptPin), MCP2515_ISR, FALLING); // start interrupt
54-
55-
5653
/*
5754
set mask, set both the mask to 0x3ff
5855
*/

0 commit comments

Comments
 (0)