Skip to content

Commit 279dcd8

Browse files
committed
refactored One Shot Mode functionality and added CANCTRL_REQOP_OSM as a CANCTRL_REQOP_MODE
1 parent ad22d13 commit 279dcd8

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ To create connection with MCP2515 provide pin number where SPI CS is connected (
5858

5959
The available modes are listed as follows:
6060
```C++
61-
mcp2515.setNormalMode();
62-
mcp2515.setLoopbackMode();
63-
mcp2515.setListenOnlyMode();
61+
mcp2515.setNormalMode(); // sends and receives data normally, sends acknowledgments to other nodes, when sending data, requires an acknowledgment from another node that the message was received or else, the 2515 will autonomously keep sending the same data
62+
mcp2515.setNormalOneShotMode(); // sends and receives data normally, sends acknoledgements to other nodes that their message was received, when sending data, does not require an acknowledgement from another node that the message was received.
63+
mcp2515.setLoopbackMode(); // data sent is immediately received and is not written to the bus, does not send acknowledgements
64+
mcp2515.setListenOnlyMode(); // does not send data, only receives data, does not send acknowledgements
6465
```
6566
The available baudrates are listed as follows:
6667
```C++

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=autowp-mcp2515
2-
version=1.2.1
2+
version=1.3.1
33
author=autowp <[email protected]>
44
maintainer=autowp <[email protected]>
55
sentence=Arduino MCP2515 CAN interface library

mcp2515.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,14 @@ MCP2515::ERROR MCP2515::setNormalMode()
177177
return setMode(CANCTRL_REQOP_NORMAL);
178178
}
179179

180+
MCP2515::ERROR MCP2515::setNormalOneShotMode()
181+
{
182+
return setMode(CANCTRL_REQOP_OSM);
183+
}
184+
180185
MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode)
181186
{
182-
modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mode);
187+
modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, mode);
183188

184189
unsigned long endTime = millis() + 10;
185190
bool modeMatch = false;
@@ -776,4 +781,4 @@ uint8_t MCP2515::errorCountRX(void)
776781
uint8_t MCP2515::errorCountTX(void)
777782
{
778783
return readRegister(MCP_TEC);
779-
}
784+
}

mcp2515.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ class MCP2515
274274

275275
enum /*class*/ CANCTRL_REQOP_MODE : uint8_t {
276276
CANCTRL_REQOP_NORMAL = 0x00,
277+
CANCTRL_REQOP_OSM = 0x08,
277278
CANCTRL_REQOP_SLEEP = 0x20,
278279
CANCTRL_REQOP_LOOPBACK = 0x40,
279280
CANCTRL_REQOP_LISTENONLY = 0x60,
@@ -473,6 +474,7 @@ class MCP2515
473474
ERROR setSleepMode();
474475
ERROR setLoopbackMode();
475476
ERROR setNormalMode();
477+
ERROR setNormalOneShotMode();
476478
ERROR setClkOut(const CAN_CLKOUT divisor);
477479
ERROR setBitrate(const CAN_SPEED canSpeed);
478480
ERROR setBitrate(const CAN_SPEED canSpeed, const CAN_CLOCK canClock);
@@ -498,4 +500,4 @@ class MCP2515
498500
uint8_t errorCountTX(void);
499501
};
500502

501-
#endif
503+
#endif

0 commit comments

Comments
 (0)