Skip to content

Commit 4ab9454

Browse files
authored
Merge pull request autowp#35 from jxltom/support-receive-both-eid-and-sid
Support receiving both standard and extended frames
2 parents 72a6877 + a1a6a32 commit 4ab9454

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

mcp2515.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,22 @@ MCP2515::ERROR MCP2515::reset(void)
4949

5050
setRegister(MCP_CANINTE, CANINTF_RX0IF | CANINTF_RX1IF | CANINTF_ERRIF | CANINTF_MERRF);
5151

52+
// receives all valid messages using either Standard or Extended Identifiers that
53+
// meet filter criteria. RXF0 is applied for RXB0, RXF1 is applied for RXB1
5254
modifyRegister(MCP_RXB0CTRL,
53-
RXBnCTRL_RXM_MASK | RXB0CTRL_BUKT,
54-
RXBnCTRL_RXM_STDEXT | RXB0CTRL_BUKT);
55-
modifyRegister(MCP_RXB1CTRL, RXBnCTRL_RXM_MASK, RXBnCTRL_RXM_STDEXT);
55+
RXBnCTRL_RXM_MASK | RXB0CTRL_BUKT | RXB0CTRL_FILHIT_MASK,
56+
RXBnCTRL_RXM_STDEXT | RXB0CTRL_BUKT | RXB0CTRL_FILHIT);
57+
modifyRegister(MCP_RXB1CTRL,
58+
RXBnCTRL_RXM_MASK | RXB1CTRL_FILHIT_MASK,
59+
RXBnCTRL_RXM_STDEXT | RXB1CTRL_FILHIT);
5660

5761
// clear filters and masks
58-
/*RXF filters[] = {RXF0, RXF1, RXF2, RXF3, RXF4, RXF5};
62+
// do not filter any standard frames for RXF0 used by RXB0
63+
// do not filter any extended frames for RXF1 used by RXB1
64+
RXF filters[] = {RXF0, RXF1, RXF2, RXF3, RXF4, RXF5};
5965
for (int i=0; i<6; i++) {
60-
ERROR result = setFilter(filters[i], true, 0);
66+
bool ext = (i == 1);
67+
ERROR result = setFilter(filters[i], ext, 0);
6168
if (result != ERROR_OK) {
6269
return result;
6370
}
@@ -69,7 +76,7 @@ MCP2515::ERROR MCP2515::reset(void)
6976
if (result != ERROR_OK) {
7077
return result;
7178
}
72-
}*/
79+
}
7380

7481
return ERROR_OK;
7582
}

mcp2515.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ class MCP2515
292292
static const uint8_t RXBnCTRL_RXM_MASK = 0x60;
293293
static const uint8_t RXBnCTRL_RTR = 0x08;
294294
static const uint8_t RXB0CTRL_BUKT = 0x04;
295+
static const uint8_t RXB0CTRL_FILHIT_MASK = 0x03;
296+
static const uint8_t RXB1CTRL_FILHIT_MASK = 0x07;
297+
static const uint8_t RXB0CTRL_FILHIT = 0x00;
298+
static const uint8_t RXB1CTRL_FILHIT = 0x01;
295299

296300
static const uint8_t MCP_SIDH = 0;
297301
static const uint8_t MCP_SIDL = 1;

0 commit comments

Comments
 (0)