From a2cece4d41ce8a03e32e401a18fe5cae09bfa7c0 Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sun, 6 Jul 2025 13:11:30 -0400 Subject: [PATCH 1/2] Update mcp2515.h added One Shot Mode flag and enable / disable methods --- mcp2515.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mcp2515.h b/mcp2515.h index 48e5d57..a9374c8 100644 --- a/mcp2515.h +++ b/mcp2515.h @@ -449,6 +449,7 @@ class MCP2515 uint8_t SPICS; uint32_t SPI_CLOCK; SPIClass * SPIn; + bool OSMflag; private: @@ -496,6 +497,8 @@ class MCP2515 void clearERRIF(); uint8_t errorCountRX(void); uint8_t errorCountTX(void); + void enableOSM(void); + void disableOSM(void); }; #endif From e1c517fc210cc3b8daf816e0c0ae7a1ef2c7141c Mon Sep 17 00:00:00 2001 From: Arduino Enigma Date: Sun, 6 Jul 2025 13:21:49 -0400 Subject: [PATCH 2/2] added One Shot Mode support --- mcp2515.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mcp2515.cpp b/mcp2515.cpp index b942b55..648b0f2 100644 --- a/mcp2515.cpp +++ b/mcp2515.cpp @@ -26,6 +26,7 @@ MCP2515::MCP2515(const uint8_t _CS, const uint32_t _SPI_CLOCK, SPIClass * _SPI) SPI_CLOCK = _SPI_CLOCK; pinMode(SPICS, OUTPUT); digitalWrite(SPICS, HIGH); + OSMflag = false; } void MCP2515::startSPI() { @@ -179,7 +180,7 @@ MCP2515::ERROR MCP2515::setNormalMode() MCP2515::ERROR MCP2515::setMode(const CANCTRL_REQOP_MODE mode) { - modifyRegister(MCP_CANCTRL, CANCTRL_REQOP, mode); + modifyRegister(MCP_CANCTRL, CANCTRL_REQOP | CANCTRL_OSM, OSMflag ? mode | CANCTRL_OSM : mode & ~(CANCTRL_OSM)); unsigned long endTime = millis() + 10; bool modeMatch = false; @@ -777,3 +778,13 @@ uint8_t MCP2515::errorCountTX(void) { return readRegister(MCP_TEC); } + +// these merely set the OSM flag +// setMode(...) or the other setXxxxMode() i.e: setNormalMode() must be called afterwards to set the correct mode with OSM +void MCP2515::enableOSM(void) { + OSMflag = true; +} + +void MCP2515::disableOSM(void) { + OSMflag = false; +}