Skip to content

Commit ef499f4

Browse files
MCP2215 on ESP32
1 parent 9d0be8a commit ef499f4

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

src/CAN.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
#ifndef CAN_H
55
#define CAN_H
66

7+
78
#ifdef ARDUINO_ARCH_ESP32
8-
#include "ESP32SJA1000.h"
9-
#else
10-
#include "MCP2515.h"
9+
//#include "ESP32SJA1000.h"
10+
#ifndef ESP32_EXTERNAL_CAN
11+
//#define IGNORE_MCP2515
12+
#endif
1113
#endif
1214

15+
#include "MCP2515.h"
16+
1317
#endif

src/MCP2515.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Sandeep Mistry. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
#ifndef ARDUINO_ARCH_ESP32
4+
#ifndef IGNORE_MCP2515
55

66
#include "MCP2515.h"
77

@@ -328,15 +328,16 @@ int MCP2515Class::parsePacket()
328328
return _rxDlc;
329329
}
330330

331+
331332
void MCP2515Class::onReceive(void(*callback)(int))
332333
{
333334
CANControllerClass::onReceive(callback);
334335

335336
pinMode(_intPin, INPUT);
336337

337338
if (callback) {
338-
SPI.usingInterrupt(digitalPinToInterrupt(_intPin));
339-
attachInterrupt(digitalPinToInterrupt(_intPin), MCP2515Class::onInterrupt, LOW);
339+
//SPI.usingInterrupt(digitalPinToInterrupt(_intPin));
340+
//attachInterrupt(digitalPinToInterrupt(_intPin), MCP2515Class::onInterrupt, LOW);
340341
} else {
341342
detachInterrupt(digitalPinToInterrupt(_intPin));
342343
#ifdef SPI_HAS_NOTUSINGINTERRUPT
@@ -345,6 +346,7 @@ void MCP2515Class::onReceive(void(*callback)(int))
345346
}
346347
}
347348

349+
348350
int MCP2515Class::filter(int id, int mask)
349351
{
350352
id &= 0x7ff;
@@ -705,11 +707,5 @@ void MCP2515Class::writeRegister(uint8_t address, uint8_t value)
705707
SPI.endTransaction();
706708
}
707709

708-
void MCP2515Class::onInterrupt()
709-
{
710-
CAN.handleInterrupt();
711-
}
712-
713-
MCP2515Class CAN;
714710

715711
#endif

src/MCP2515.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Sandeep Mistry. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
#ifndef ARDUINO_ARCH_ESP32
4+
//#ifndef IGNORE_MCP2515
55

66
#ifndef MCP2515_H
77
#define MCP2515_H
@@ -81,17 +81,14 @@ class MCP2515Class : public CANControllerClass {
8181
void modifyRegister(uint8_t address, uint8_t mask, uint8_t value);
8282
void writeRegister(uint8_t address, uint8_t value);
8383

84-
static void onInterrupt();
85-
8684
private:
8785
SPISettings _spiSettings;
8886
int _csPin;
8987
int _intPin;
9088
long _clockFrequency;
9189
};
9290

93-
extern MCP2515Class CAN;
9491

9592
#endif
9693

97-
#endif
94+
//#endif

0 commit comments

Comments
 (0)